Help with jQuery Ajax calling ASMX which returns string.
- by Jason Evans
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.