开发者

Help with jQuery Ajax calling ASMX which returns string

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 co开发者_Python百科de, 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜