Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 08:20:31 10月05日 Update

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!

Tags: Methods functions foreground parameters background tutorials content form learning practical ordinary deeper interest practical practical simple operation data more best friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi MariaDB OPPO Reno Linux