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);}
}