Common Page Submission Methods
This article summarizes the common Page Submission methods.
When it comes to common usage, you should pay attention to it. If the method you choose is not commonly used, you should consider your own design or program. We still need to stand on the shoulders of giants to create good things.
In fact, several methods described in this article are commonly used.
Common is to do the right thing when appropriate. The right technology, used in the right place, is a good design; like the right time, to meet the right people with the same spirit.
Method 1:
Common form submission.
In this way, the page will jump. In this mode, you can select the post or get submission method. Generally, you can submit the form generic post method. This method is very common.
var form = document.getElementById(frm01); form.action =<%=basePath %>test/productShow.action; form.method = post; form.submit();
Method 2:
The merging parameter is behind the url.
This method is the get submission method. The parameters are listed after the url. This method is also the most commonly used, but you must pay attention to the confidentiality of the transmitted parameters and the parameter length restrictions.
window.location.href=<%=basePath%>test/productDetails.shtml?productId=+$(#productId).val() +&detailUrl=+$(#detailUrl).val() ;
Method 3:
Use Ajax to submit a form.
In this way, the entire frm01 will be submitted and refreshed locally. If you need to jump to a page, you can also jump to the page in success function in combination with other page Jump methods.
$.ajax({ type:'post', url: '<%=basePath %>test/productShow.shtml', data:$(#frm01).serialize(), dataType:'json', cache: false, success : function(data) {} });
Method 4:
Submit Ajax concatenation parameters.
This method is similar to the above method, but it is equivalent to concatenating parameters after the url. Instead of submitting the entire form. Similarly, in this way, the page is not redirected and partial refreshing is performed.
$(.send_msg).click(function(){ $.ajax({ type:'post', async:true, url: <%=basePath%>test/productShow.shtml, data:product.productId=+$(#productId).val() +&product.productName=+ $(#productName).val()+&product.logo=+$(#logo).val(), dataType:'json', cache: false, success : function(data) {} });})
Method 5:
Submit multiple options.
$(#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(); });
Method 6:
After you jump to the page, the system automatically submits the page and completes the jump.
This method is generally used in the payment of page jumps.
<Script type = text/JavaScript> mainform. submit (); </script>
Summary:
1. In order to avoid the form set, we can construct a newForm, assign the required parameters through js, and submit the newForm;
2. Some parameters are not suitable for transferring between pages, such as the amount of an order and the number of purchased items, so that I can closely transfer them, then, go to the database to query [pay attention to data consistency issues]. analyze the specific issues;
3. When appropriate, use the appropriate technology. after such a long period of time, you can enjoy the ease of use. Otherwise, we will continue to accumulate experiences of failures.