Publish the common PAGE method as WebMethod and access it in Javascript format.
1. The method must be public static. The return type is preferably string.
2. Add the [WebMethod] feature before the method.
3. The Post method must be used for Client access to interact with Json as data. Otherwise, the entire page of HTML is returned.
4. During jQuery access, data. d In the callback is actually returned.
5 The access URL is: http://abc.com/abc.aspx/GetTime if there is a GetTime public static method.
Example:
Abc. aspx
[WebMethod] public static string GetTime () {return DateTime. Now. ToString ("yyyy-MM-dd HH: mm: ss ");}
---------------
Script (called using jQuery as an example)
$. Ajax ({url: url, method: "post", dataType: "json", contentType: "application/json; charset = UTF-8", success: function (data) {$ ("# id" pai.html (data. d); // see }});