PageMethods无法在asp.net中运行 [英] PageMethods is not working in asp.net

查看:98
本文介绍了PageMethods无法在asp.net中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PageMethods从客户端调用服务器端方法,但是我遇到一个问题,即服务器端方法只调用,如果我从源代码部分调用方法,如果我使用相同的javascript制作javascript文件代码并将链接添加到页面然后它不起作用,只有PageMthods不工作但javascript文件的所有其他东西工作正常。



请建议怎么做我解决了这个问题。



谢谢

Prafulla

I am using PageMethods to call server side method from client side but I am getting a problem that server side method is calling only if, I am calling the method from source part, if i am making a javascript file with the same javascript code and adding the link into the page then it is not working, only PageMthods is not working but all other thing of javascript file is working fine.

Please suggest how would I resolve this issue.

Thanks
Prafulla

推荐答案

试试这个.. :)



Javascript




try this.. :)

Javascript


function GetName() {


.ajax({
type: POST
url: Default.aspx / GetData // Pagename / Functionname
contentType: application / json; charset = utf-8
data:{}, // data
dataType: json
成功: function (data){

alert(data.d);

},
错误:功能(结果){

alert( 错误

}
});
}
.ajax({ type: "POST", url: "Default.aspx/GetData", //Pagename/Functionname contentType: "application/json;charset=utf-8", data: {},//data dataType: "json", success: function (data) { alert(data.d); }, error: function (result) { alert("error") } }); }





HTML





HTML

<span onclick="GetName()">Call Web Method</span>





C#





C#

[WebMethod]
      public static string GetData()
      {
          string name= "My name is Nirav Prabtani";

          return name;
      }


嗨朋友,



不应该影响在页面级别或脚本文件中保存脚本。

检查一次天气你给出了正确的文件或任何其他语法。



它是好的用Firebug找到错误..!
Hi Friend,

It should not affect weather keeping script in page level or in script file.
Check once weather you gave right file or any other syntax.

it is good to find the error with Firebug..!


这篇关于PageMethods无法在asp.net中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆