Markuz Shultz
Markuz Shultz

Reputation: 678

How to create JSONP callback?

I have JSON file generated on my server , but I want to access that data from other host . What should I do on my server , or JSON file to make that data accessible from other domains like JSONP ?

Upvotes: 1

Views: 1262

Answers (2)

Brad Christie
Brad Christie

Reputation: 101594

Assuming it's exposed by some web-accessible method, you need to accept a callback (or similar) parameter which then just becomes a wrapper to the JSON data. e.g.

If you had:

/some/service.json

Which returned:

{"this":"is","JSON":"data"}

You then allow the service to be passed a callback:

/some/service.json?callback=foo

Which in turn results in:

foo({"this":"is","JSON":"data"})

That's all there really is to making the response adhere with JSONP.

Upvotes: 1

Umesh Panchani
Umesh Panchani

Reputation: 440

i think this below code help you

$.ajax({
    type: "POST",
    url: "xyz.com",
    data: jsondata,
    dataType: "jsonp",
    success: function(data) {

        if(data.flag == true){

            alert(data.msg);


        } else {
            alert("not sucess");

        }
    }

    }); 

Upvotes: 0

Related Questions