views:

172

answers:

2

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

+1  A: 

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).

T.J. Crowder
Checked it and even changed it to single quotes but makes no difference.It seems something to do with allowing scripts from a domain since it is working under IE and Opera not with firefox and safari. But have no idea yet how to check it and change it.
Erald
@Erald: Very strange. I'm not seeing anything else obvious, whatever the issue is, I don't think it's in the quoted code -- something elsewhere on the page must be having an odd side-effect. Good luck with it.
T.J. Crowder
A: 

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.

tugboat