jQuery的阿贾克斯导致在Firefox刷新整个页面 [英] jQuery's ajax is causing a full page refresh in FireFox

查看:139
本文介绍了jQuery的阿贾克斯导致在Firefox刷新整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Ajax调用。 Ajax调用工作正常,在IE 7,但Firefox 3一直在做这个电话时,做了整页刷新。 AJAX调用被发布到一个ASP.NET页面的方法。

I'm making an ajax call with jQuery. The ajax call works fine in IE 7, but FireFox 3 always does a full page refresh when making this call. The ajax call is POSTing to an ASP.NET page method.

是否有jQuery的一个问题,还是我只是缺少一些设置?

Is there a problem in jQuery or am I just missing some setting?

$.ajax({
async: false,
type: "POST",
url: "Default.aspx/DoSomething",
data: "{" + parms + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function(data) { succesfulPost(data); },
error: function(XMLHttpRequest, textStatus, errorThrown) { errorPost(textStatus, errorThrown); }

});

该呼叫正在从HTML按钮onclick事件。我试过'返回false;'在方法是使这一AJAX调用,但在Firefox中完全刷新继续。

The call is being made from an html button onclick event. I tried the 'return false;' in the method that is making this ajax call, but the full refresh in FireFox continues.

我试过设置异步=真实的,但似乎并没有工作。火狐只是不断前​​进,不等待后端返回响应。火狐(在js的)实际上是发生在AJAX调用错误。正如你可以在上面看到,误差函数的定义,当我设置异步这是触发=真。

I've tried setting async = true, but that doesn't seem to work. FireFox just keeps going and doesn't wait for the backend to return a response. FireFox (in js) actually is generating an error in the ajax call. As you can see above, the error function is defined and this is triggered when I set async = true.

推荐答案

返回false是你所需要的,但是如果出现一个JavaScript错误,你打的前行,那么浏览器将继续执行一个链接点击或按钮-Click事件得很开心。

return false is what you need, however if a javascript error occurs before you hit that line, then the browser will continue on carrying out a link-click or button-click event happily.

您可以试试环绕的潜在问题try / catch块。

you can try try surround potential problem areas with try/catch blocks.

另外,你可以试试这个:

Alternatively you might try this:

即preventDefault 的处理函数中的第一条语句。这是应该发生停止默认情况下,我想你可以调用这个前面...我只是还没有尝试过。

e.preventDefault as the first statement in your handler. This is supposed to stop the default event from happening, and i think you can call this up front... I just haven't tried it.

编辑:我也想补充的是,AJAX错误:处理程序只捕获错误来自服务器......像403或500。你还是应该包装在一个try / catch Ajax调用

I'd also like to add that the ajax error: handler only traps errors that come from the server... like a 403 or 500. You should still wrap the ajax call in a try/catch.

这篇关于jQuery的阿贾克斯导致在Firefox刷新整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆