3

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);
1
  • Try using a relative Url, in case the browser thinks theres some kind of XSS going on here: url: "/NotificationChecker.ashx", Commented Oct 5, 2012 at 9:51

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I think your ajax call is missing the following:

    dataType: 'json',
    contentType: "application/json; charset=uft-8",

1 Comment

In this case how can I retrieve the posted arguments? Because the only thing that changes is that on the server side I can't retrieve Request["userName"] parameter.
0

Try this:

$.ajax({ 
        url: "/NotificationChecker.ashx",
        dataType: 'json',
        contentType: "application/json; charset=uft-8",      
        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 });
}

Comments

0

I think your problem is that you pass your username like this

data: { userName: "ggyimesi" }

I think you should do it like this

data: '{userName:"' + ggyimesi + '"}'

and you can add more like this

 type: "POST",
 url: "NotificationChecker.ashx",
 contentType: "application/json; charset=utf-8",
 dataType: 'json',

1 Comment

this case I can't seem to find any passed parameters on the asp.net side. Request paremeters and inputstream is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.