Jsonp 不能与 getJSON jquery 一起使用
Jsonp not working with getJSON jquery
$(document).ready(function() {
$.getJSON("http://quanta.net16.net/wordpressnew/test.php?jsoncallback=?", function(data) {
alert('swag');
});
});
这是我的 JSON 调用,我的 JSON 正确包装在 ?({对象}(但是警报没有弹出,它没有显示任何JavaScript错误请帮助解决任何可能的修复问题链接到创建 PHP 的 JSON如果需要,URL 是开放的
请求的输出为:
?([{"id":84,"title":"Solar Decathlon","url":"http:'/'/quanta.net16.net'/wordpressnew'/wp-content'/uploads'/2015'/12'/grp4_s2.jpg","isFeatured":false,"isNews":false,"college":false,"time":1450076653,"summary":""},{"id":80,"title":"HUDCO UNIT 2012-13","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1450076349,"summary":"HUDCO UNIT 2012-13 got the first citation in 55th annual NASA convention 2012-13 for their design of 24*7 day and night permanent shelter for urban homeless.The entire work is taken by HUDCO,New delhi to work more on it.Also the entire work has been asked to sent by Dr.amod kumar from st.stefens hospital,tiss hazati, Delhi. and […]"},{"id":77,"title":"Egyptian Artwork","url":"http:'/'/quanta.net16.net'/wordpressnew'/wp-content'/uploads'/2015'/12'/XU0zTIXjslCgCGAULTlAVz3AEbLzNFdsB1OVFJH7zWYw222-h220.jpg","isFeatured":false,"isNews":false,"college":false,"time":1450075669,"summary":"Made By the students of all the batch 3102 etc,this is some artwork info.Made By the students of all the batch 3102 etc,this is some artwork infoMade By the students of all the batch 3102 etc,this is some artwork infoMade By the students of all the batch 3102 etc,this is some artwork infoMade By the […]"},{"id":67,"title":"Collezione – 2015","url":"http:'/'/quanta.net16.net'/wordpressnew'/wp-content'/uploads'/2015'/12'/event2015.jpg","isFeatured":false,"isNews":false,"college":false,"time":1450074883,"summary":"Collezione – 2015 the Annual Fashion Show of the School Of Fashion & Textile Design, The new age designers put a jaw dropping collections, for various category of Indian Ethnic, Resort, Cruize, Swimwear, Westernwear formal & men'u2019s wear."},{"id":63,"title":"International Tour: 'u201cWorld is a book, those who do no travel read only one page'u201d 'u2013 St. Agustine","url":"http:'/'/quanta.net16.net'/wordpressnew'/wp-content'/uploads'/2015'/12'/irfw_23.jpg","isFeatured":false,"isNews":false,"college":false,"time":1450071633,"summary":"True to ever word, students along with our experienced faculty get to have a great exposure to world of Fashion Art & Design. We host premium events with visits to Premier Vision, Art galleries, Meeting Designers and much more for an unmatched international exposure and witness latest in fashion, upcoming trend & So forth. Come […]"},{"id":53,"title":"yoloswag asdfasdfa","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1449835439,"summary":"asdfasdf"},{"id":50,"title":"asdf","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1449834299,"summary":"asdfasdfasdasdfasdfasdfsdfasd"},{"id":48,"title":"asdfasdf","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1449834004,"summary":"asdfasdfasdfasdf"},{"id":45,"title":"asdfasdfasdfasdfad","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1449833570,"summary":"adsfasdfasdfasdfasdfasdfasdf"},{"id":43,"title":"Story of my life","url":false,"isFeatured":false,"isNews":false,"college":false,"time":1449830857,"summary":""}]);
这不是一个有效的JavaScript。函数调用不能以 ?()
开头。相反,我会要求你创建一个使用它的函数,比如:
function callJson (data) {
alert(data.length);
console.log(data.length);
}
现在,只需向以下人员提出请求:
http://quanta.net16.net/wordpressnew/test.php?jsoncallback=callJson
这给出了输出,callJson({json-data})
.
工作片段
$(function () {
function callJson (data) {
alert(data.length);
console.log(data.length);
}
$.getJSON("https://jsonp.afeld.me/?url=http://quanta.net16.net/wordpressnew/test.php?jsoncallback=callJson", function (data) {
debugger;
}).fail(function(data) {
// console.log( data );
res = data.responseText.trim().replace("callJson(", "");
res = res.substr(0, res.length-2);
res = JSON.parse(res);
console.log(res);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
更正了代码段。检查控制台。
我没有正确设置跨源资源共享标头
相关文章:
- 将jQuery UI Timepicker Addon与React一起使用
- 将FormParams与Jersey和jQuery一起使用
- 将Jquery与wordpress主题一起使用
- 存储数据的最佳方式是什么,以便与jquery一起使用
- 将jQuery.css()与变量一起使用
- 如何将jquery ui与requirejs一起使用
- 注入的元素和jQuery脚本.如何让他们一起工作
- 有条件地创建ajax url参数以与jQuery Validate一起使用
- 在使用 Django 静态文件时动态设置映像时,只有绝对路径才能与 jquery 一起使用
- 使一组对象与 jQuery 一起拖动
- 将 jQuery UI 日期选择器与异步 AJAX 请求一起使用
- 通过 jQuery Find and Replace 将文本 URL 与 标记包装在一起
- 将jQuery动画与angular的ngAnimate一起使用
- 将 jQuery trigger() 与 hoverIntent 一起使用
- Jquery 工具提示未随 AJAX 数据加载一起显示
- Jquery animate 不能与 IE 一起使用 - 什么也没发生
- jQuery脚本不想一起工作
- While循环与jquery中的某些数学函数一起崩溃
- 合并多个画布在一个单一的DIV一起- JQuery
- 如何让两个框架拖在一起?(jQuery)