简体   繁体   English

jQuery ajax调用在Firefox浏览器中不起作用

[英]JQuery ajax calls not working in Firefox browser

I am trying to test Jquery ajax calls in Firefox but it it not working. 我正在尝试在Firefox中测试Jquery ajax调用,但是它不起作用。 I mean my server is not receiving any requests. 我的意思是我的服务器没有收到任何请求。 But when I test in IE8 it works fine. 但是当我在IE8中进行测试时,它可以正常工作。 Here is my ajax call: 这是我的ajax电话:

$("#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". 从我的服务器代码(java),我将内容类型设置为“ 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作为对象传递,如下所示:

data: {cityName: $cityName},

Have you installed Firebug ? 您安装了Firebug吗?

Your best bet would be to install Firebug, which comes with a console that'll notify you of any javascript errors. 最好的选择是安装Firebug,它带有一个控制台,该控制台会通知您任何JavaScript错误。 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) 据我所知,您的代码看起来不错(除了@Nick Craver指出的可能问题)

Also, why the '$' on your cityName variable? 另外,为什么在cityName变量上使用“ $”? The '$' prefix in Javascript is meant to be reserved for machine-generated code (so that it has no chance of conflicting with user code). Javascript中的'$'前缀是为机器生成的代码保留的(这样就不会与用户代码冲突)。

try installing firebug plugin in ff :: https://addons.mozilla.org/en-US/firefox/addon/1843/ 尝试在ff :: https://addons.mozilla.org/zh-CN/firefox/addon/1843/中安装firebug插件

Then check the :::: Net Tab >> All selected 然后检查::::网络选项卡>>全部选中

Refresh the page and see is your ajax call actually getting called. 刷新页面,看看实际上是您的ajax调用被调用了。 If yes is there any syntax error in the call or any variable null error. 如果是,则调用中是否存在语法错误或任何变量null错误。 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. 通常,当我最终遇到parseerror ,这意味着返回标头类型错误,或者服务器以某种方式发送了带有响应的额外数据。 For instance, if I'm looking to get JSON back and I get the JSON and some HTML from x-debug. 例如,如果我想找回JSON,并且从x-debug获得JSON和一些HTML。

Also, The OPTIONS request is for cross-domain requests which is what @Nick was alluding to. 此外, OPTIONS请求是针对跨域请求的,这是@Nick暗示的内容。

A helpful link to get you started . 帮助您入门的有用链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM