Ajax Submission Method

Source: Internet
Author: User

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

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.