ArticleDirectory
- 1. Ajax library Method
- 2. jquery Method
- 3. There is also a good example of referencing the Ajax. dll file. register the foreground method in the background. This seems to be a lot of use in. net2.0. I did not study it carefully.
Call the static method in the background from the client
1. Ajax library Method
C #Code:
[Webmethod] public static datetime getcurrenttime (string Str) {return datetime. Now ;}
JS Code:
<Form ID = "form1" runat = "server"> <script language = JavaScript type = "text/JavaScript"> function getcurrenttime1 () {pagemethods. getcurrenttime ('newegg Ajax training ', checkissuccess);} function checkissuccess (result) {alert (result) ;}</SCRIPT> <div> <asp: scriptmanager id = "scriptmanager1" runat = "server" enablepagemethods = "true"> </ASP: scriptmanager> <input id = "button1" type = "button" value = "client control call server method" onclick = "getcurrenttime1 () "/> </div> </form>
Note:
C # "[webmethod]" must be added to the Method
The front-end page must use the reference Server Control
<Asp: scriptmanager id = "scriptmanager1" runat = "server" enablepagemethods = "true">
</ASP: scriptmanager>
Call method: pagemethods. Name of the background method (parameter [, parameter...], name of the method called after the call is successful );
Ajax Library
2. jquery Method
C # code:
[Webmethod] public static string ABC (string ABC) {return ABC ;}
JS Code:
$ (). Ready (function () {$ ("# ajaxdemo "). click (function () {$. ajax ({type: "Post", URL: "default. aspx/ABC ", data:" {'abc': 'test'} ", contenttype:" application/JSON; charset = UTF-8 ", success: function (MSG) {alert (MSG );}})})})
Note: The jquery library file must be referenced.
3. There is also a good example of referencing the Ajax. dll file. register the foreground method in the background. This seems to be a lot of use in. net2.0. I did not study it carefully.
I also hope you can talk to each other in other simpler ways ~