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 ?
2 Answers
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.
Comments
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");
}
}
});
1 Comment
Brad Christie
This is client-side; My understanding is that the OP was asking how to make it available from server-side.