I’m writing a client for an asp.net handler that processes and sends notifications to the polling clients. I make ajax calls with jquery every 10 seconds waiting for the notifications. The problem is every time I send a response back to the client it always calls the error callback. With fiddler I see the json response arriving to the client with status 200 but in firebug the request keeps waiting.
Client:
function poll(){
$.ajax({
url: "http://localhost:53914/NotificationChecker.ashx",
data: { userName: "ggyimesi" },
type: 'POST',
success: function(data){
alert("asd");
$('div#mydiv').text(data.Text);
},
complete: poll,
error: function(data){alert(data.status);},
timeout: 15000 });
}
$(document).ready(function(){
poll();}
);
Server:
Response response = new Response();
response.Text = this.MessageText;
response.User = Result.AsyncState.ToString();
string json = JsonHelper.JsonSerializer<Response>(response);
Result.Context.Response.ContentType = "application/json";
Result.Context.Response.Write(json);
I actually found the problem. The problem was that I started the client html from my local machine not hosted on the web server and that caused the problem. After adding it to the local web server the original code worked as it is.