的WebMethod不会被调用 [英] WebMethod not being called
本文介绍了的WebMethod不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我传递包含字符串通过jquery.ajax服务器javascript变量。虽然成功状态被呼叫时,服务器端的WebMethod不会被调用。客户:
$阿贾克斯({
类型:后,
网址:Playground.aspx / childBind
数据:{送出数据:ID},
//的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:TEXT,
成功:函数(结果){警报(成功了!+ result.d); }
})
服务器:
[的WebMethod]
公共静态字符串childBind(字符串送出数据)
{
返回的String.Format(你好);
}
解决方案
尝试下面为您的Ajax请求修正:
$阿贾克斯({
类型:后,
网址:Playground.aspx / childBind
数据:{送出数据:+身份证+'},
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON
成功:函数(结果){警报(成功了!+ result.d); }
})
改变的通知的dataType
和数据
值作为一个字符串。
I am passing a javascript variable containing a string to the server via jquery.ajax. Although the "success" condition is called, the server-side WebMethod is never called. Client:
$.ajax({
type: "post",
url: "Playground.aspx/childBind",
data: {sendData: ID},
//contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) { alert("successful!" + result.d); }
})
Server:
[WebMethod]
public static string childBind(string sendData)
{
return String.Format("Hello");
}
解决方案
Try following fixes for your Ajax request:
$.ajax({
type: "post",
url: "Playground.aspx/childBind",
data: "{sendData: '" + ID + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) { alert("successful!" + result.d); }
})
Notice changed dataType
and data
value as a string.
这篇关于的WebMethod不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文