JS Ajax foreground How to give the background class function pass parameter _ajax correlation

Source: Internet
Author: User

The normal page method is advertised as WebMethod and is accessed in JavaScript form.

1 method to public static decoration, the return type is best string.
2 method before adding the [WebMethod] attribute.
3 client-side Access uses the Post method to interact with JSON as the data form. Otherwise, the entire page of HTML is returned.
4 in jquery access, the DATA.D in the callback is the true return of the content.
5 Access URL is: http://abc.com/abc.aspx/GetTime if there is a GetTime public static method.

Cases:
Abc.aspx

[WebMethod]
public static string GetTime ()
{return
DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss");
}

---------------
Script (called in jquery)

$.ajax ({
Url:url, method
: "Post",
DataType: "JSON",
contentType: "Application/json; Charset=utf-8 ",
success:function (data) {
$ (" #id "). HTML (DATA.D);/See 3rd
}
});

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.