1

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 ?

4

2 回答 2

1

假设它是通过一些 Web 可访问的方法公开的,您需要接受一个callback(或类似的)参数,然后该参数将成为 JSON 数据的包装器。例如

如果你有:

/some/service.json

哪个返回:

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

然后,您允许将服务传递给callback

/some/service.json?callback=foo

这反过来导致:

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

这就是使响应符合 JSONP 的全部内容。

于 2013-07-08T13:40:12.533 回答
0

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");

        }
    }

    }); 
于 2013-07-08T13:41:41.767 回答