Sometimes when writing a Web application, you need to dynamically construct a form and submit it, the parameters and action in the form, the POST request or get request, and even the style of the form can be specified, which can certainly be done with native JavaScript, I did a test with jquery.
My own test is to construct a paging post request, in order to prevent the CSRF attack, joined the CSRF verification, do not need to be removed.
Example
Function gensearchobj (Url,page,pagesize,keyword) { var params = {};
params.url = url;
params.page = page;
params.pageSize = pageSize;
params.cond = keyword;
return params; } function mockformsubmit (params) { var form = $ (' <form /> ', {action : params.url, method: ' Post ', style: ' Display:none; '}. Appendto (' body '); $.each (Params, function (k, v) { if ( k != "url" ) { form.append (' <input type = "hidden" name= "' + k + '" " value=" ' + v + ' "&nbsP;/> ');
} }); form.append (' <input type= "hidden" name= "Csrftoken" value= "" + "
$ ("#csrf_token"). Val () + ' /> ' );
form.submit (); }
Example 2
<! doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http:// Www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
You need to add the created form to the DOM, and the browser renders it to respond to events and methods. Tmpform.appendto (document.body). Submit ();