且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Java脚本调用C#代码

更新时间:2023-12-05 12:58:52

是的,您可以使Web方法类似..您可以创建Web服务来调用服务器端代码
yes, you can make web method like.. you can create web service to call to server side code
[WebMethod]
public static String SetName(string name)
{
    return "Your String"
}



然后像这样调用javascript.



and then call in javascript like..

PageMethods.SetName(parameterValueIfAny, onSuccessMethod,onFailMethod);



这也是必需的



this also required

<asp:scriptmanager id="ScriptMgr" runat="server" enablepagemethods="true" xmlns:asp="#unknown"> </asp:scriptmanager>


请参考以下主题:
如何在服务器后面调用代码客户端javascript函数提供的方法 [从Java脚本函数调用C#代码背后的方法 [通过ASP中的Javascript调用C#函数. NET [使用jQuery调用ASP.NET AJAX页面方法–通过示例 [
Please refer following threads:
How to call code behind server method from a client side javascript function[^]
call a C# code behind method from a Java Script function[^]
Calling C# function through Javascript in ASP.NET[^]
Using jQuery to Call ASP.NET AJAX Page Methods – By Example[^]


有几种方法通过客户端与服务器端进行交互(Javascript):
1. XMLHttpRequest [回调 [ Web服务调用 [ PageMethod [
There are few ways to interact with server side through client side(Javascript):
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]