Trouble with JQuery Ajax / ASP.Net


I'm having some trouble getting some ajax functionality to work in all browsers.  The code IS working correctly in IE8 and Firefox.  However, it is not working in Chrome, Safari, or Opera.

Below is my JavaScript (i.e. using jquery-1.4.3):
var ResponseTimer = "";

$(document).ajaxError(function (e, xhr, settings, exception) {
    alert('error in: ' + settings.url + ' \nerror: ' + exception + '\nxhr status: ' + xhr.status);

function StartResponseTimer()
    alert('CIP Settings have been sent. Awaiting response from control.');


    //Start javascript poll timer:
    //ResponseTimer = setInterval('CheckForControlRepsonse()', 2000);

function CheckForControlRepsonse()
        type: 'GET',
        async: true,
        url: 'http://localhost:52971/AjaxResponder.aspx?CallingPage=CIP',
        dataType: 'html',
        timeout: 0,
        success: function (responseData) { ProcessAjaxResponse(responseData); }

function ProcessAjaxResponse(responseData)
    if (responseData != 'no-response')
        //If ACK or NCK received then stop timer:

        //Display messages to user:
        var message = '';
        if (responseData == 'ACK') message = 'CIP Settings Received By Control.';
        if (responseData == 'NCK') message = 'An error occured when atempting to send CIP\r\n settings to control. Please try again.';

Open in new window

And here is my server side code that is handling the ajax request:
namespace XXXXXXXXXX
    public partial class AjaxResponder : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            string CallingPage = Request.QueryString["CallingPage"].ToString();

            switch (CallingPage)
                case "HOME": HomeResponder(); break;
                case "CIP": CIPResponder(); break;

        private void HomeResponder()

        private void CIPResponder()
            string response = "";

            //ToDo: Get response message from listener server.

            response = "ACK";

            if (response != "") Response.Write(response);
            else Response.Write("no-response");

Open in new window

When I run the site in IE8 or Firefox I get a javascript popup saying: "CIP Settings Received By Control." Which is just what I expect to get.

When I run the site in Chrome or Safari, I get a popup showing:

    Error in: http://localhost:52971/AjaxResponder.aspx?CallingPage=CIP
    error: undefined
    xhr status: 0

Which would be the ajaxError() handler being executed.

When I run the site in Opera, I get nothing.....

Please advise as to what I'm not doing correctly.  Thanks.
LVL 10
Who is Participating?
JosephEricDavisConnect With a Mentor Commented:
Try changing your dataType to text instead of html
P1ST0LPETEAuthor Commented:
Tried changing the dataType to text.  Results didn't change a bit.
P1ST0LPETEAuthor Commented:
Figured out the issue on my own.  Button I was using to kick off the javascript was also kicking off a standard asp postback of it's own.  This was causing the XmlHttpResponse.status attribute to = 0, and fouling up the ajax all together.  Separated the code out so things weren't happening at the same time, and everything works.

Thanks for the help though Joseph.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.