$ .getJSON parsererror试图调用API [英] $.getJSON parsererror trying to call API

查看:113
本文介绍了$ .getJSON parsererror试图调用API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用裁剪API( http://clipped.me/api.html)返回JSON,但我遇到了一些麻烦。我使用的getJSON,并在Chrome的JS控制台我得到这些错误信息:

I'm trying to use the Clipped API (http://clipped.me/api.html) that returns JSON but am running into some trouble. I'm using getJSON, and in Chrome's JS console I get these error messages:

资源间preTED为脚本,但使用MIME类型text / html转移的http://clipped.me/algorithm/clippedapi.php?url=callback=jQuery1910859611126…emo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/&_=1364420105379\".

Resource interpreted as Script but transferred with MIME type text/html: "http://clipped.me/algorithm/clippedapi.php?url=callback=jQuery1910859611126…emo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/&_=1364420105379".

未捕获的SyntaxError:意外的标识符

Uncaught SyntaxError: Unexpected identifier

请求失败:parsererror,错误:jQuery19108596111265942454_1364420105378不叫

Request Failed: parsererror, Error: jQuery19108596111265942454_1364420105378 was not called

这是我的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在所有的东西,所以我真的不知道该怎么在这里做。我试着周围的Googling,但不能发现任何东西。说我实际发送的数据是过得去出现这种jQuery的通知切断当我添加回调=?

This is my first time trying to make something with an API or JSON at all, so I'm really not sure what to do here. I've tried Googling around but can't find anything. The data that I'm actually sending is getting cut off by this jQuery notice that appears when I add callback=?

推荐答案

您参数将不是简单的猜测[URL]参数是什么。试试这个:

Your parameter will not simply "guess" what the [URL] param is. Try this:

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并没有提供一个访问控制允许来源头。因此,你有两个选择:

Even this fails, however, as your API endpoint does not seem to understand/support JSONP and does not provide a Access-Control-Allow-Origin header. You therefore have two choices:


  • 您可以反向代理的本地API来绕过跨域问题,并通过标准的JSON

  • 您可以... ... EHM获得更好的API?递交票与开发者得到它排序。

这篇关于$ .getJSON parsererror试图调用API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆