Javascript Webmethod不适用于jquery
我在Jquery中使用webmethod。我在success函数中编写了一个警报,我在运行项目时收到了该警报,但我的Webmthod没有调用,因此代码对我来说不起作用。我在Webmethod中给degub加了一个点,但没有成功。我没有收到任何错误,也没有收到我的方法调用。 下面是我的Jquery和Webmethod代码:Javascript Webmethod不适用于jquery,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我在Jquery中使用webmethod。我在success函数中编写了一个警报,我在运行项目时收到了该警报,但我的Webmthod没有调用,因此代码对我来说不起作用。我在Webmethod中给degub加了一个点,但没有成功。我没有收到任何错误,也没有收到我的方法调用。 下面是我的Jquery和Webmethod代码: <script type='text/javascript' src="Scripts/jquery-1.4.1.min.js"></script>
<script type='text/javascript' src="Scripts/jquery-1.4.1.min.js"></script>
function onDialogClosed(sender, args) {
$(document).ready(function () {
$.ajax({
type: "POST",
url: "SpellChecker.aspx/Save",
data: { DocName: $("#txttest").val() },
success: function (msg) {
alert($("#txttest").val());
},
error: function (a,b,c) {
alert(a+ b+ c);
}
});
});
}
尝试以下方法:
1.启用从脚本调用Webmethod,使用:
[System.Web.Script.Services.ScriptService]
2.启用Web服务页面方法在带有脚本的页面上调用:
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true">
</cc1:ToolkitScriptManager>
希望这有帮助 尝试如下所示,按以下格式指定内容类型、数据类型和数据。它对我有用
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "order_form.aspx/GetAutoCompleteData",
data: '{DocName: "' + $("#txttest").val() + '" }',
dataType: "json",
success: function(data) {
//response(data.d);
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
您是否尝试过使用firebug检查ajax,如果是的话,结果是什么。您是在同一个页面(.aspx)中创建webmethod还是在不同的.asmx文件中创建webmethod?嗨@Dave:我使用firebug调试了代码,我成功地将debbuger放到了debbuger中,it调试程序成功了,但我的webmethod不起作用,还有一件事(成功:函数(msg))作为msg,我得到了整个html页面。
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "order_form.aspx/GetAutoCompleteData",
data: '{DocName: "' + $("#txttest").val() + '" }',
dataType: "json",
success: function(data) {
//response(data.d);
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});