美元.试图调用API时出现错误
$.getJSON parsererror trying to call API
我试图使用Clipped API (http://clipped.me/api.html),返回JSON,但我遇到了一些麻烦。我使用getJSON,并在Chrome的JS控制台我得到这些错误信息:
资源被解释为脚本,但以MIME类型text/html: "http://clipped.me/algorithm/clippedapi.php?url=callback=jQuery1910859611126...emo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/&_=1364420105379"传输。
Uncaught SyntaxError: Unexpected identifier
请求失败:parsererror, Error: jQuery19108596111265942454_1364420105378未被调用
这是我的JS:
var clippedAPI = "http://clipped.me/algorithm/clippedapi.php?url=[URL]callback=?";
$.getJSON(clippedAPI, "http://pandodaily.com/2013/03/26/y-combinator-demo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/" ).done(function(json) {
console.log("JSON Data: " + json.title );
}).fail(function(jqxhr, textStatus, error){
var err = textStatus + ', ' + error;
console.log("Request Failed: " + err);
});
这是我第一次尝试用API或JSON做一些事情,所以我真的不知道该怎么做。我试着用谷歌搜了一下,但什么也找不到。我发送的数据会被这个jQuery通知截断当我添加callback=?
您的参数不会简单地"猜测"[URL]参数是什么。试试这个:
var clippedAPI = "http://clipped.me/algorithm/clippedapi.php";
$.ajax({
url: clippedAPI,
type: "GET",
dataType: "JSONP",
data: {
url: "http://pandodaily.com/2013/03/26/y-combinator-demo-day-2013-still-looking-for- the-next-airbnb-or-dropbox/"}
}).done(function(json) {
console.log("JSON Data: " + json.title );
}).fail(function(jqxhr, textStatus, error){
var err = textStatus + ', ' + error;
console.log("Request Failed: " + err);
});
即使这样也失败了,因为您的API端点似乎不理解/支持JSONP,并且不提供Access-Control-Allow-Origin
标头。因此,您有两个选择:
- 您可以在本地反向代理API以绕过跨域问题并通过标准JSON
- 你可以…………记得不能用获得更好的API?向开发人员提交一张票,让他们把它分类。
相关文章:
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 使用Yelp API时出现OAuth错误
- internet explorer 8兼容模式下的Youtube api错误
- 使用FB.ui的Facebook Feed对话给出API错误191
- DreamFactory REST API POST休息/用户/会话请求总是在IE9中返回错误
- 我该如何解决“;未捕获引用错误:谷歌没有定义"?(谷歌地图API)
- "未捕获的语法错误:意外的标记<"当尝试使用谷歌'核心报告API
- json-api和错误结果:无法读取属性'长度'的未定义
- 向Yahoo Finance API发出JSONP请求时获得400错误请求
- 使用javascript API响应内部服务器错误将曲目上传到SoundCloud
- 使用Google Analytics API的区域图-未采集类型错误无法读取'库'的未定义
- 使用gmail-api发送电子邮件错误:此api不支持解析表单编码的输入
- AWS API网关返回400错误请求,但Postman工作正常
- Javascript:可驱动api出现禁止的错误
- YouTube API v3哈希标签搜索错误结果
- 使用Twitter API进行推文时出现重复状态错误
- 岗位http://localhost:3000/api/signup400(错误请求)
- Google嵌入API cb=gap对象错误
- 科尔多瓦指南针 API 给出错误代码 3
- 在 api 调用$resource显示错误和成功消息