开发者

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: 开发者_StackOverflow社区"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?


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},


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜