Help with jQuery Ajax calling ASMX which returns string.

Posted by Jason Evans on Stack Overflow See other posts from Stack Overflow or by Jason Evans
Published on 2010-06-01T09:36:04Z Indexed on 2010/06/01 9:53 UTC
Read the original article Hit count: 280

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about jquery-ajax

Related posts about asmx