views:

139

answers:

1

Hi there.

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.

+1  A: 

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.

Martin
+ 1 I just ran the page in FireFox (to test out your idea of using Firebug) and the Ajax call works fine. So I thought it could be an IE problem - just tried the page again in IE (without VS debugging) and the Ajax call works. Hmm, maybe a red-herring in that it could be VS that was causing the problem. I'll keep an eye on this, but thanks for the above tip.
Jason Evans