jQuery ajax调用不在FF中工作,safari在IE中工作

时间:2010-03-08 17:20:57

标签: jquery jquery-validate

我制作了一个小模块,在我的网站上使用jquery / ajax脚本。为此,我使用了网站上的示例和其他示例。该脚本在IE中工作(对于它在那里工作的更改)但我不能让它在FF或safari中工作。尝试了很多东西,但不知怎的,它永远不会执行updatecounter函数 我不是一个javascript程序员,所以不知道在哪里看。也许有些人知道我做错了什么 试过

if (Drupal.jsEnabled) {
$(document).ready(function(content) {
$('a.download').click(function () {
// This function will get exceuted after the ajax request is completed successfully
var updatecounter = function(data) {
alert (data.counter); // only in IE this is displayed not in FF or Safari
}
alert(this.href); // this works in all browsers
var urlget = "/counter/get”;
$.ajax({
type: 'GET',
url: urlget,
success: updatecounter, // The js function that will be called upon success request
dataType: 'json', //define the type of data that is going to get back from the server
data: 'js=1' //Pass a key/value pair
});
//return false; // return false so the navigation stops here and not continue to the page in the link .. This puzzles me also. If I put it in the program stops and does not continue
});
});
}

奇怪的是,如果我把它改为:

if (Drupal.jsEnabled) {
$(document).ready(function(content) {
$('a.download').click(function () {
// This function will get exceuted after the ajax request is completed successfully
var updatecounter = function(data) {
alert (data.counter); // only in IE this is displayed not in FF or Safari
}
var fout = function(stat, statext) {
alert (stat.readyState);
alert (statext);
}

alert(this.href); // this works in all browsers
var urlget = "/counter/get”;
$.ajax({
type: 'GET',
url: urlget,
success: updatecounter, // The js function that will be called upon success request
error: fout , // calls when error
dataType: 'json', //define the type of data that is going to get back from the server
data: 'js=1' //Pass a key/value pair

});
//return false; // return false so the navigation stops here and not continue to the page in the link .. This puzzles me also. If I put it in the program stops and does not continue
});
});
}

它总是转到fout并显示错误代码4和文本错误。所以ajax调用正在工作,但总是给我错误(仅在FF和safari中不在IE中)

我正在尝试这几个小时也许有人可以帮助我在这里 感谢

2 个答案:

答案 0 :(得分:1)

您是否已将页面中的代码复制并粘贴到问题中?因为如果是这样的话,它就是在这一行使用(花式关闭引用)而不是"(直引号):

var urlget = "/counter/get”;

如果这是问题的一部分,我不会感到惊讶,这不是终止字符串的有效方法(但是,使用一些键盘布局,这是一个容易犯的错误)。

答案 1 :(得分:0)

我刚遇到这个问题 - 我的解决方案是变量名。 Safari很好,我使用'text'作为变量名称(我知道,我很邋),但它在FF中出错了。

我发布这个并不是因为我认为这必然是上述问题的解决方案,但是万一有人发现这个帖子并且犯了类似的错误。

相关问题