Ajax Submission Method
In WebForm development, we often use Ajax to the background to submit data, in my company, usually submitted to the background of this page to deal with, or WebService, both methods are simple, but always seem slightly confusing.
Today, while looking at the BlogEngine, I found out that it was handled like this.
First of all, use a ajaxhelper.asp tutorial x page to handle all the Ajax requests, and the background of this page is all:
[WebMethod]
public static Jsonresponse Savepage (
String ID,
String content,
String title,
String description,
String keywords,
String Slug,
BOOL Isfrontpage,
BOOL Showinlist,
BOOL Ispublished,
String parent)
{
Webutils.checkrightsforadminpagespages (FALSE);
var response = new Jsonresponse {success = false};
var settings = blogsettings.instance;
if (String.IsNullOrEmpty (ID) &&!security.isauthorizedto (rights.createnewpages))
{
Response.message = "Not authorized to create new pages."
return response;
}
....
WebMethod, so in fact and webservice no essential difference, but more refreshing than the WebService
And see how the front desk handles it:
...
var dto = {
"id": QueryString (' ID '),
"Content": content,
"title": Title,
"desc": Desc,
"slug": slug,
"Tags": tags,
"Author": Author,
"Ispublished": ispublished,
"Hascommentsenabled": hascommentsenabled,
"Cats": Cats,
"Date": Date,
' Time ': Time
};
Alert (Json.stringify (DTO));
$.ajax ({
URL: ".. /ajaxhelper.aspx/savepost ",
Type: "Post",
DataType: "JSON",
ContentType: "Application/json; Charset=utf-8 ",
Data:json.stringify (DTO),
Success:function (Result) {
var rt = RESULT.D;
if (rt.success) {
if (rt.data) {
Window.location.href = Rt.data;
} else {
Showstatus ("Success", rt.message);
}
}
Else
Showstatus ("Warning", rt.message);
}
});
...
A standardized AJAX submission processing mechanism that is much better than random abuse