First, as Bradley explained, fix the syntax of the JSONP file - it needs those parentheses. That's because the file needs to be valid JavaScript code. JSONP is just a convention for using a JavaScript function call to load JSON data from a script file.
If the file will remain static - in particular if the name of the mycallback
function is hard coded - then you should probably just treat it as a script file that calls a global function, because that's what it really is. Define a global function named mycallback
, and use $.getScript()
to load your static JSONP/JavaScript file:
window.mycallback = function( data ) {
alert( data.toSource() );
};
$.getScript( 'http://www.remote-server/jsonp-test.php' );
Note that you don't need the ?callback=mycallback
for a static file either.