views:

101

answers:

4

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?

+1  A: 

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},
Nick Craver
I have changed code as you suggested. Still server is not receiving any requests but error function is calling. It says "parseerror" when I say alert('ERROR['+textStatus+']');
goutham
@goutham - What port is the webpage on? If it's not `:8080`, it'll get an empty response, resulting in a parser error due to the same origin policy
Nick Craver
Yes it is 8080.
goutham
+1  A: 

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).

Dean Harding
+1 it should be `var cityName = "New York";`
aSeptik
I have corrected this now it says "parseerror" when I say alert('ERROR['+textStatus+']') in error function.
goutham
A: 

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

J Sinh
I have Firebug, but under URL, it shows as "OPTIONS WeatherServlet" I am not sure this is causing somethig. It should be "POST" right?
goutham
A: 

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.

Gutzofter