|
$. Ajax ({
// Submit the address
Url :"",
// Submitted data
Data: {key1: value1, key2: value2, key3: value3, key4: value4 },
// Events before submission
BeforeSend: function (){
Login. hide ();
ShowInfo.html (loginInfo );
},
// Submission method
Type: "POST ",
// Submitted data type
DataType: "json ",
// Events after submission
Success: function (result ){
If (result. State. toString () = "success" & result. IsLogin. toString () = "1 "){
ShowInfo. addInfoMsg ("logon successful! Redirecting ...");
Window. location. href = "/Default. aspx ";
}
Else {
Login. show ();
ShowInfo. addShowMsg (result. exMsg. toString ());
}
},
// Submission error time
Error: function (httpRequest, textStatus, errorThrown ){
ShowInfo. addShowMsg ("system error. Please log on again! ");
Login. show ();
}
});
Returned data format:
// Format of the returned data
Var returnInfo = "\" State \ ": \" {0} \ ", \" IsLogin \ ": \" {1} \ ", \" exMsg \": \ "{2 }\"";
Context. Response. Write ("{" + String. Format (returnInfo, "success", "1", "login successful! ") + "}");
Context. Response. Write ("{" + String. Format (returnInfo, "fail", "0", "username cannot be blank") + "}");
Context. Response. Write ("{" + String. Format (returnInfo, "fail", "0", "password cannot be blank") + "}");
Context. response. write ("{" + String. format (returnInfo, "fail", "0", "you are not authorized to log on to the system. Contact your administrator. ") + "}");
Context. Response. Write ("{" + String. Format (returnInfo, "fail", "0", "illegal login," + ex. Message + "}")); |