admin管理员组文章数量:1180511
I have this code:
<script src=".7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.getJSON('', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
How can I change this code:
<script>
$(document).ready(function() {
$.getJSON('', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
for it to work as JSONP ... Is this totally different?
I have this code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.getJSON('http://example.com/api/get_cats', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
How can I change this code:
<script>
$(document).ready(function() {
$.getJSON('http://example.com/api/get_cats', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
for it to work as JSONP ... Is this totally different?
Share Improve this question edited Mar 19, 2016 at 12:35 rrk 15.8k4 gold badges30 silver badges47 bronze badges asked Aug 11, 2012 at 18:53 Satch3000Satch3000 49.4k89 gold badges224 silver badges349 bronze badges 3 |1 Answer
Reset to default 35Actually, you just have to add ?callback=?
, jQuery does the rest.
$(document).ready(function() {
$.getJSON('http://example.com/api/get_cats?callback=?', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
本文标签: javascriptChanging getJSON to JSONPStack Overflow
版权声明:本文标题:javascript - Changing getJSON to JSONP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738214271a2069177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<script>
request. The response must have the data wrapped in a function call, likemy_func({"foo":"bar"})
. Then when the script arrives, assuming there's a function namedmy_func
, that function is invoked passing the data into it. Some servers let you specify the function name, and they'll return the JSONP response, but this behavior must be established on the server. – user1106925 Commented Aug 11, 2012 at 19:25