Heim  >  Artikel  >  Web-Frontend  >  常用的页面提交方式_html/css_WEB-ITnose

常用的页面提交方式_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:49:20909Durchsuche

本文来总结一下,常用的页面提交方式。

提到常用,大家就要注意了。如果你选用的方式不常用,那么你就该思量一下自己的设计或者程序了。还是要站在巨人的肩膀上,才能创造出好的东西。


其实,本文将要讲的几种方式都比较常用。

常用就是合适的时候,做合适的事情。合适的技术,用在合适的地方,就是好的设计;就像合适的时间,遇到合适的人一样心有灵犀。


方式一:

常用的form提交。

该种方式提交页面,页面会进行跳转。这种方式可以选择post提交方式,还是get提交方式,一般情况下,提交form通用post。这种方式,很常用。

var form = document.getElementById("frm01");            form.action ="test/productShow.action";            form.method = "post";            form.submit();


方式二:

拼接参数在url后面。

这种方式,为get提交方式。参数会列在url后面。该种方式同样最常用,但是要注意传递的参数的保密性,以及参数的长度限制。

window.location.href="test/productDetails.shtml?productId="+$("#productId").val() +"&detailUrl="+$("#detailUrl").val() ; 


方式三:

Ajax提交form的方式。

这种方式,会提交整个frm01,并且局部刷新。如果需要页面跳转,也可以结合其他页面跳转的方式,在success的function中进行页面跳转。

$.ajax({                 	type:'post',                     url: 'test/productShow.shtml',                      data:$("#frm01").serialize(),                     dataType:'json',                       cache: false,                      success : function(data) {}  });


方式四:

Ajax拼接参数提交。

该种方式,类似上面的方式,只不过是相当于将参数拼接在url后面。而不是整个form提交。同样,该种方式,页面不会进行跳转,且局部刷新。

$(".send_msg").click(function(){	    		 $.ajax({	             	type:'post',	             	async:true,	                url: "test/productShow.shtml",	                data:"product.productId="+$("#productId").val() +"&product.productName="+      	                        $("#productName").val()+"&product.logo="+$("#logo").val(),	               	dataType:'json',  	                cache: false,	                success : function(data) {}  	             });})


方式五:

多项选择时,提交。

$("#realBuy").bind("click",function(){          			var ids=new Array();          			var itemNos=new Array();          			$(".payItemBox ul li").filter(".selected").each(function(index){          				ids.push($(this).prev().prev().val());          				itemNos.push($(this).prev().val());          			});          			$("input[name='theoryrepayids']").val(ids.join(","));          			$("input[name='itemNos']").val(itemNos.join(","));          			$("input[name='total']").val(sum.toFixed(2));          			$("#repForm").submit();          		});


方式六:

跳到该页面后,自动提交,并完成跳转。

该种方式,一般在做支付跳页时用。




总结:

1、为了避免form套form的情况,我们可以构造一个newForm,将需要的参数,通过js赋值过去,提交这个newForm即可;

2、有些参数,不适合在页面之间传来传去,比如一个订单的金额、购买的数量之类的,那么我就可以紧着重要的传递,然后再到数据库中查询【注意数据一致性的问题】,具体问题具体分析;

3、合适的时候,使用合适的技术,这样时间长了,才能做到游刃有余。不然就是南辕北辙,不断积累失败的经验。


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn