Ajax submission URL is related to the detailed comparison of the AJAX submission Form _ajax

Source: Internet
Author: User

1:ajax constructs a URL that passes parameters to data and cannot be used for form submission.
Cases:

Copy Code code as follows:



function createhtml (ID) {


$ ("#reloading"). Show ();


EDIT_BG is a div, displayed when submitted, so that the background page cannot be manipulated.


$ ("#edit_bg"). Show ();


$.ajax ({


Type: "POST",


URL: "Pageaction!createhtml.action",


Data: "Id=" +id,


Success:function (data) {


$ ("#reloading"). Hide ();


$ ("#edit_bg"). Hide ();


if (data = = "true") {


Alert ("Operation succeeded.") ");


}else{


Alert ("Operation failed, please contact admin!") ");


}


Operation after successful operation


});


}





2:ajax submit form, which is very useful for large data transfer, such as user registration, information is very large, with Ajax submission form, the page is more beautiful but, for Ajax submission form, we have to introduce a JS, namely: Jquery.form.js "


Cases:


Copy Code code as follows:



function UploadFile () {





$ ("#reloading"). Show ();


$ ("#edit_bg"). Show ();


Form1 for Table Single-name


$ ("#form1"). Ajaxsubmit ({


Type: "POST",


Success:function (data) {


$ ("#reloading"). Hide ();


$ ("#edit_bg"). Hide ();


if (Data.indexof ("true")!=-1) {


Alert ("Operation succeeded.") ");


}else{


alert (data);


Alert ("Operation failed, please contact admin!") ");


}


Operation after successful operation


});


}





3:2 items in the AJAX submission form, although the correct operation, but the data returned by the problem, the page can not be processed results. The following code corrects the AJAX submission form


Copy Code code as follows:



function SubmitForm () {


$ (' #form1 '). Ajaxsubmit (ajaxoptionsnew);


}





var ajaxoptionsnew = {


Beforesubmit:fn_check_form,


Success:showresponse,


URL: "Costation!save2.action",


Error:function (xmlresponse) {


alert (Xmlresponse.responsetext);


Alert (' Operation failed! ');


Window.location.reload ();


}


};

function Fn_check_form () {
if ($ ("#Name"). val () = "") {
Alert ("Man cannot be empty");
$ ("#Name"). focus ();
return false;
}
}

function Showresponse (responsetext) {


try{


alert (responsetext);


if (ResponseText = = ' true ') {


Alert (' Operation successful! ');


Window.location.reload ();


}


else if (responsetext = ' paramfalse ')


{


Alert ("Required parameter cannot be empty!")


}


else if (responsetext = ' timeerror ')


{


Alert ("Departure time cannot be greater than reimbursement time!");


}


else{


Alert (' Operation failed! ');


Window.location.reload ();


}


}catch (e) {alert (e.message);}


}


Related Article

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.