JSONP - Link to JSON data file?

JSONP - Link to JSON data file?

axdaxd Posts: 2Questions: 1Answers: 0


I'm trying to get my head around server side loading and I'm not quite grasping the info on this page -

It looks to me like the Javascript links to the php file (the code in the Server Side Script tab), but nothing links to the JSON data source (the data in the AJAX tab)... Is that right?

I'm pretty comfortable with something like this (in Javascript):

    $('#example').DataTable( {
        "ajax": "url: link/to/file/data.json"
    } );

But if I want to serve the data.json file from a different server, then I add a php file to my server but how / where do I link to the data.json file? Trying to recreate the files in the example linked above gives me the error message Ajax error. For more information about this error, please see datatables.net/tn/7

What am I missing? My apologies if it's something basic; I've always been more front-end focused but I'm trying to learn a bit more back end lately



  • colincolin Posts: 3,631Questions: 0Answers: 638

    Hi @axd ,

    This thread here should help - if not, shout back,



  • axdaxd Posts: 2Questions: 1Answers: 0

    Thanks for that @colin ! That thread was a little advanced for me but I think I've got my head around it now.

    For anyone else reading this, this article helped too

  • allanallan Posts: 48,902Questions: 1Answers: 7,131 Site admin

    JSONP is effectively a method to get around cross site scripting. The "trick" is that you need to be in control of the remote server you are loading data from so you can tell it what function it should call when the data is returned.

    Using CORS headers on the remote server is a better option these days.


Sign In or Register to comment.