jgg
jgg

Reputation: 1136

JQuery ajax calls not working in Firefox browser

I am trying to test Jquery ajax calls in Firefox but it it not working. I mean my server is not receiving any requests. But when I test in IE8 it works fine. Here is my ajax call:

$("#getWeatherReport").click(function(){
                $cityName = "New York";
                $.ajax({
                    type: "POST",
                    dataType:"xml",
                    url: "http://localhost:8080/Test/WeatherServlet",
                    data: "cityName="+$cityName,
                    success: function(data) {
                        alert($("report", data).text());
                    },
                    error: function(xhr, textStatus, errorThrown) {
                        alert('ERROR['+xhr.statusText+']');
                    }
                });
            });

It is not even calling error function. And from my server code(java) I am setting content type as "text/xml". Any suggestions?

Upvotes: 1

Views: 11340

Answers (4)

Gutzofter
Gutzofter

Reputation: 2023

Usually, when I end up with a parseerror that means that the return header type is wrong or that somehow the server sent extra data with the response. For instance, if I'm looking to get JSON back and I get the JSON and some HTML from x-debug.

Also, The OPTIONS request is for cross-domain requests which is what @Nick was alluding to.

A helpful link to get you started.

Upvotes: 0

Jsinh
Jsinh

Reputation: 2579

try installing firebug plugin in ff :: https://addons.mozilla.org/en-US/firefox/addon/1843/

Then check the :::: Net Tab >> All selected

Refresh the page and see is your ajax call actually getting called. If yes is there any syntax error in the call or any variable null error. If all is fine then you can think of further issues

Upvotes: 1

Dean Harding
Dean Harding

Reputation: 72638

Have you installed Firebug?

Your best bet would be to install Firebug, which comes with a console that'll notify you of any javascript errors. You can also use it (via the "Net" tab) to monitor all requests made by your page.

From what I can see, your code looks OK (other than the possible issue pointed out by @Nick Craver)

Also, why the '$' on your cityName variable? The '$' prefix in Javascript is meant to be reserved for machine-generated code (so that it has no chance of conflicting with user code).

Upvotes: 2

Nick Craver
Nick Craver

Reputation: 630349

Your string is not correctly serialized, I'm not sure if that's the issue, but it may be and it's definitely a potential one for later, try this for an immediate test:

var $cityName = "New+York";

As a more permanent solution, pass data as an object, like this:

data: {cityName: $cityName},

Upvotes: 2

Related Questions