Hi,
This is about a tangled cluster of XHR and WebMethod (asmx). The pattern is simple, I make calls via XHR to Webmethod, but it seems WebMethod are sync not async. I just need to make this transition asynchronous. I am searching and searching (might be not good in search) but couldn't find anything that can resolve this mystery.
Here, how I makes calls via XHR:
$.ajax = {
pool: [],
call: function(settings, onSuccess, onFailure) {
var xhr = new XMLHttpRequest();
xhr.open(settings.type, settings.location, settings.async);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var result = xhr.responseXML.xml.toString();
onSuccess($.Encoder.htmlDecode(result));
}
};
$.ajax.pool.push(xhr);
xhr.send(null);
return xhr;
}
}
Then:
$.ajax.call({ type: "get", location: "Index.asmx/RaiseCallbackEvent?eventArgument=ramiz.uddin" , async: true }, function(e) {}, function(e){})
The webservice is fairly simple too:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public string RaiseCallbackEvent(string eventArgument)
{
// some logic
return "<say>hello</say>";
}
And some web.config entries that allows POST, GET calls:
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
Could you please guide me what I've to do for asynchronous?
Thanks.