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

发布于 2024-08-24 03:21:57 字数 2120 浏览 4 评论 0原文

我制作了一个小模块来在我的网站上使用 jquery/ajax 脚本。为此,我使用了网站和其他网站上的示例。该脚本可以在 IE 中运行(进行更改后可以在 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中)

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

I made a little module to use a jquery/ajax script on my website. For that I used examples which are on the site and others. The script is working in IE (for a change it works there) but I cannot get it working in FF or safari. Tried a lot of things but somehow it never executes the updatecounter function
I am not a javascript programmer so have no idea where to look. Maybe there are some who know what I am doing wrong
Tried

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
});
});
}

Strange thing is if I change the it to :

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
});
});
}

It always goes to fout and displays error code 4 and text error. So the ajax call is working but gives me always and error (only in FF and safari not in IE)

I am trying on this for some hours maybe someone can help me out here
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-08-31 03:21:57

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

var urlget = "/counter/get”;

如果这是一部分,我不会感到惊讶就问题而言,这不是终止字符串的有效方法(尽管对于某些键盘布局来说这是一个很容易犯的错误)。

Did you copy-and-paste that code from your page into the question? Because if so, it's using a (fancy close-quote) rather than a " (straight quote) on this line:

var urlget = "/counter/get”;

I wouldn't be surprised if that were part of the problem, that's not a valid way to terminate the string (an easy mistake to make, though, with some keyboard layouts).

失与倦" 2024-08-31 03:21:57

我刚刚遇到了这个问题——我的解决方案是变量名。 Safari 可以接受我使用“text”作为变量名(我知道我很马虎),但它在 FF 中给出了错误。

我发布此内容并不是因为我认为这必然是上述问题的解决方案,而是以防万一有人发现此线程并犯类似的错误。

I just had this problem -- and my solution was in the variable names. Safari was fine with me using 'text' as a variable name (sloppy of me, I know), but it gave an error in FF.

I'm posting this not because I think this is necessarily the solution to the problem above, but just in case someone finds this thread and is making a similar mistake.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文