Use jQuery to reuse form forms and asynchronously submit them to other actions, jqueryform

Source: Internet
Author: User

Use jQuery to reuse form forms and asynchronously submit them to other actions, jqueryform
During page development, sometimes the form data must be reused and asynchronously submitted to other links, in this case, you can use jquery to modify the form's action value (remember to modify it back) and call the submit method. Of course, the return value type of the link action or controller Method in the background must be void, otherwise, a page Jump occurs. If the return value is null, a blank page is displayed, and asynchronous calling cannot be implemented. In addition, you can use another method to submit, serialize the form, and then use jQuery's ajax to submit, but you need to process the returned information. Directly add the Code: (1) jQuery changes the form attribute

$ (". ExportBrandSort "). on ('click', function () {var url = contextPath + "/brand/exportBrandSort"; $ ('# searchform '). attr ('action', url); $ ('# searchform '). submit (); // restore the action value url = contextPath + "/brand/getBrand"; $ ('# searchform '). attr ('action', url );});

(2) Ajax submission method
$(".exportBrandSort").on('click', function() {         var url = contextPath+"/brand/exportBrandSort";     var data= $('#searchform').serialize();        $.ajax({      type: 'GET',      url: url,      data: data,      success:function(retJson){          }    });    });



Jquery asynchronously submits the form, and then obtains the returned results. The language environment jsp, java, and MVCAction receives and submits the results.

Well, you can't try this. Define a <iframe name = 'den den _ framework' id = "hidden_frame" style = 'display: none'> </iframe> on the page, and then write Response at the end of the controller. write ("<script> parent. show_msg ('"+ showInfoStr +"') </script> ");
Configure in the form as follows: enctype = "multipart/form-data", target = "hidden_frame"
Show_msg is a page script function.
In this case, jquery asynchronous commit is not required.
I am working on. net. In. net, this is acceptable. I think java should also be fine. That is, the form setting attribute. I don't know how to write it in java.

Use jquery asynchronous form submission in struts2

Before answering your questions, you must clarify one question:
Struts and jquery are not directly related. They only interact with each other through http at runtime. Therefore, they do not understand what you call "Do not manually PASS Parameters, but still use the struts2 feature ", do not say "use jquery in struts2 ".

If you do not want to obtain parameters manually every time when using jquery ajax requests, you must create a rule and then perform a conversion on jquery. For example, you can encapsulate a function: each time the input field data in the page form is automatically obtained, the parameters are assembled in the ajax request and submitted to the background, so that you do not need to manually obtain parameters for each form submission.
However, if your ajax request parameters do not have any regularity, or some parameters are randomly added according to the logic at the time, how can you let the program automatically collect and submit parameters for you. We must recognize a problem: any so-called automation reflects the laws and rules logic, and anything that cannot be abstracted into rules cannot be automated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.