I have a page that calls an external application.js. This external application.js file should call an external join.js (hosted on a third party domain) and place it inside a given div on the page i.e. #myGivenId.
Updated: Simplified problem explanation.
The join.js file simple return a document.write('something here'); string. The something here text should be placed inside the #myGivenId
I’m tried the following code but the result does not appear to be rendered on the page nor appears on the source code.
// jQuery version
$(document).ready(function() {
return $.getScript('http://localhost:3001/ads/join.js', function(script) {
return $('#myGivenId').html(script);
});
});
// CoffeScript version
$(document).ready ->
$.getScript('http://localhost:3001/ads/join.js', (script) -> $('#myGivenId').html(script))
Any idea why is not appearing?
jQuery’s
$.getScriptdoes not return data that way, you need to provide a callback.reference: http://api.jquery.com/jQuery.getScript/