帮助 jQuery Ajax 调用返回字符串的 ASMX
我有以下 jQuery ajax 调用设置:
function Testing() {
var result = '';
$.ajax({
url: 'BookingUtils.asmx/GetNonBookableSlots',
dataType: 'text',
error: function(error) {
alert('GetNonBookableSlots Error');
},
success: function(data) {
alert('GetNonBookableSlots');
result = data;
}
});
return result;
}
这是我尝试调用的 Web 服务:
[WebMethod]
public string GetNonBookableSlots()
{
return "fhsdfuhsiufhsd";
}
当我运行 jQuery 代码时,没有触发任何错误或成功事件(没有调用任何警报)。事实上,什么也没有发生,JavaScript 代码只是继续到最后的 return 语句。
我在 Web 服务代码中放置了一个断点,它确实被击中,但是当我离开该方法时,我最终还是会出现 return 语句。
有人可以给我一些关于如何正确配置 ajax 调用的提示,因为我觉得我做错了。 Web 服务只需要返回一个字符串,不涉及 XML 或 JSON。
干杯。 贾斯。
I have the following jQuery ajax call setup:
function Testing() {
var result = '';
$.ajax({
url: 'BookingUtils.asmx/GetNonBookableSlots',
dataType: 'text',
error: function(error) {
alert('GetNonBookableSlots Error');
},
success: function(data) {
alert('GetNonBookableSlots');
result = data;
}
});
return result;
}
Here is the web service I'm trying to call:
[WebMethod]
public string GetNonBookableSlots()
{
return "fhsdfuhsiufhsd";
}
When I run the jQuery code, there is no error or success event fired (none of the alerts are called). In fact, nothing happens at all, the javascript code just moves on to return statement at the end.
I put a breakpoint in the web service code and it does get hit, but when I leave that method I end up on the return statement anyway.
Can someone give me some tips on how I should be configuring the ajax call correctly, as I feel that I'm doing this wrong. The webservice just needs to return a string, no XML or JSON involved.
Cheers.
Jas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是为了调试尝试这个:
使用 Firebug 或 HTML Inspector 控制台查看输出。此外,Firebug 或 HTML Inspector 还可以为您提供有关问题所在的其他线索。您可以检查返回的结果以查看是否存在 HTTP 错误。
Just for debugging try this:
Use the Firebug or HTML Inspector console to view the output. As well, Firebug or HTML Inspector can give you other clues to what the problem is. You can inspect the returned result to see if there was an HTTP error.