帮助 jQuery Ajax 调用返回字符串的 ASMX

发布于 2024-09-04 10:29:22 字数 892 浏览 2 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮烟 2024-09-11 10:29:22

只是为了调试尝试这个:

$.post('BookingUtils.asmx/GetNonBookableSlots', function(data) {
    console.log(data);
}, 'text);

使用 Firebug 或 HTML Inspector 控制台查看输出。此外,Firebug 或 HTML Inspector 还可以为您提供有关问题所在的其他线索。您可以检查返回的结果以查看是否存在 HTTP 错误。

Just for debugging try this:

$.post('BookingUtils.asmx/GetNonBookableSlots', function(data) {
    console.log(data);
}, 'text);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文