JQuery的阿贾克斯Firefox的错误 [英] JQuery Ajax Firefox Error
问题描述
下面code正常工作在这两个浏览器和IE浏览器
$得到(../ AJAX / BTBookAppointment.aspx DSL =?+ telNumberBox.value +&放大器;日期=+ requiredDate.value +&放大器;时隙= + ddTimeslot.value,函数(响应状态,XHR){
//做一些东西
});
不过在Firefox(11.0版)的回调函数永远不会打。我已经使用萤火有一个断点,并已确认是从来没有进入回调。该网页似乎刷新,这是由JavaScript的pviously显示$ P $再次变为可见的元素。
我在一个无所适从的错误可能是甚至如何进一步调试。任何意见将是AP preciated。
修改:提琴手和萤火虫从来没有表现出一个HTTP GET。我也试着写了$。获得明确(见下文),并获得相同的行为
EDIT2:我曾尝试达林季米特洛夫提到的建议,它仍然exibits相同的行为(页回按钮被点击时)。这里是code,因为它主张。
Javascript的
函数bookAppointment(){
VAR URL =../ajax/BTBookAppointment.aspx;
VAR DSL =01753893530
VAR日期=20-04-2012;
变种时隙=下午;
VAR数据= {DSL:DSL,日期:日期,时隙:时隙};
$阿贾克斯({
网址:../ajax/BTBookAppointment.aspx
数据:数据,
成功:函数(响应状态,XHR){
警报('变成回调');
},
});
返回false;
}
HTML
<按钮ID =btnBookAppointment的onclick =bookAppointment();>图书< /按钮>
我不知道为什么,但它似乎按钮仍然触发在FF的默认行为(回发),即使bookAppointment()返回false。添加一回假的按钮固定的东西(见下文)。
<按钮ID =btnBookAppointment的onclick =bookAppointment();返回false;>
The below code works fine in both Chrome and IE
$.get("../ajax/BTBookAppointment.aspx?dsl=" + telNumberBox.value + "&date=" + requiredDate.value + "×lot=" + ddTimeslot.value, function (response, status, xhr) {
//DO some stuff
});
However in Firefox (Version 11.0) the callback function is never hit. I have used firebug with a breakpoint and have verified the callback is never entered. The page seems to refresh, an element that was previously shown by JavaScript becomes visible again.
I'm at a loss as to what the bug could be or even how to debug it further. Any advice would be appreciated.
EDIT: Fiddler and firebug never show a HTTP get. I have also tried writing out the $.get explicitly (see below) and get the same behaviour
EDIT2: I have tried the suggestions mentioned by Darin Dimitrov and it still exibits the same behavior (the page posts back when the button is clicked). Here is the code as it stands.
Javascript
function bookAppointment() {
var url = "../ajax/BTBookAppointment.aspx";
var dsl = "01753893530"
var date = "20-04-2012";
var timeslot = "PM";
var data = { dsl: dsl, date: date, timeslot: timeslot };
$.ajax({
url: "../ajax/BTBookAppointment.aspx",
data: data,
success: function (response, status, xhr) {
alert('into callback');
},
});
return false;
}
HTML
<button id="btnBookAppointment" onclick="bookAppointment();"> Book</button>
I don't know why but it seems the button was still triggering the default behavior (a postback) in FF even when bookAppointment() returned false. Adding a return false to the button fixed things (see below).
<button id="btnBookAppointment" onclick="bookAppointment();return false;">
这篇关于JQuery的阿贾克斯Firefox的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!