Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JS AJAX foreground method tutorial for passing parameters to functions of background classes

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "JS AJAX foreground to the background class function transfer parameter method tutorial", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "JS AJAX foreground to the background class function transfer parameter method tutorial" it!

Publish the method of a normal page as WebMethod and visit it as Javascript.

1 the method needs to be modified by public static, and the return type is preferably string.

Add the [WebMethod] attribute before the 2 method.

(3) when accessing the Client, use the Post method to interact with Json as data. Otherwise, the full page HTML will be returned.

4 when the jQuery is accessed, the data.d in the callback will actually return the content.

5 access URL: 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");}

-

Script (called with jQuery as an example)

Ajax ({url:url,method: "post", dataType: "json", contentType: "application/json; charset=UTF-8", success: function (data) {$("# id") .html (data.d); / / see point 3}}); at this point, I believe you have a deeper understanding of the "JS AJAX foreground to the background class function parameter transfer method tutorial", might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report