Home > Web Front-end > JS Tutorial > How does the JS AJAX frontend pass parameters to the function of the background class?

How does the JS AJAX frontend pass parameters to the function of the background class?

高洛峰
Release: 2017-02-16 17:28:34
Original
1521 people have browsed it

This article mainly introduces the method of passing parameters from the JS AJAX frontend to the function of the background class. There is a good example below. Friends who need it can refer to

to publish the methods of ordinary pages as WebMethod. Accessed as Javascript.

1 The method must be decorated with public static, and the return type is preferably string.
2 Add the [WebMethod] attribute before the method.
3 When accessing the client, use the Post method to interact with Json as data. Otherwise, the entire page of HTML will be returned.
4 When accessed by jQuery, data.d in the callback is the real return content.
5 The access URL is: http://abc.com/abc.aspx/GetTime If there is a public static method of GetTime.

Example:
abc.aspx


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


----------- ----
Script (call jQuery as an example)


$.ajax({
url:url,
method:"post",
dataType:"json",
contentType:"application/json; charset=UTF-8",
success: function(data){
$("#id").html(data.d); //见第3点
}
});
Copy after login

For more related articles on how the JS AJAX front-end passes parameters to the functions of the background class, please visit Follow PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template