JSON callback called in IE but not FireFox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jeff00seattle
Forum Commoner
Posts: 66
Joined: Sat Feb 28, 2009 3:27 pm

JSON callback called in IE but not FireFox

Post by jeff00seattle »

I am working on service that is using a JSON endpoint and I am providing it with a JavaScript callback function. The callback function is called in IE (8) but not in FireFox (3.5.3).

The source point to receive the callback is as follows in the body of the page:

Code: Select all

<script id="SearchCallback" type="text/javascript" src="">
</script>
The JSON URL with callback doStuff() is assigned to this source point as follows:

Code: Select all

document.getElementById("SearchCallback").src = json_url_w_callback;
And using online HTTP viewer: http://www.httpviewer.net/, the JSON URL with callback doStuff() returns the following JavaScript code:

Code: Select all

if(typeof doStuff == 'function') doStuff( /* JSON Results */ );
Ideas why the callback doStuff() is not getting called in FireFox?

Thanks

Jeff in Seattle
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: JSON callback called in IE but not FireFox

Post by kaszu »

Instead of changing src of existing SCRIPT element, create new and change that elements source

Code: Select all

var script = document.createElement('SCRIPT');
script.type = "text/javascript";
script.src = json_url_w_callback;
document.body.appendChild(script);
jeff00seattle
Forum Commoner
Posts: 66
Joined: Sat Feb 28, 2009 3:27 pm

Re: JSON callback called in IE but not FireFox

Post by jeff00seattle »

Thanks,

This worked great!

Jeff in Seattle
Post Reply