我正在使用以下代码进行跨域JSONP调用:
jQuery.ajax({
async: true,
url: 'http://mnews.hostoi.com/test.json',
dataType: 'jsonp',
method: "GET",
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus + ': ' + errorThrown);
},
success: function (data, textStatus, jqXHR) {
if (data.Error || data.Response) {
exists = 0;
}
}
});
Run Code Online (Sandbox Code Playgroud)
在Firebug中调试时,我收到以下错误:
SyntaxError: missing ; before statement
Run Code Online (Sandbox Code Playgroud)
但是,当我通过像jsonlint.com这样的工具传递我的json对象(通过JQ代码中的链接可用)时,它说它是有效的JSON.我也没有发现任何异常现象.怎么会返回语法错误?它是一些JSONP细节我没有得到或什么?
{"news":[ {
"sentences": [
"Neuroscientists have discovered abnormal neural activity...",
"The researchers found that these mice showed many symptoms...",
"\"Therefore,\" the study authors say, \"our findings provide a novel.."
],
"summaryId": "ZJEmY5", …
Run Code Online (Sandbox Code Playgroud) 我有一段(jQuery)ajax代码,在过去几周左右的时间里已经开心工作了大约9个月.
此代码使用Instagram的嵌入端点,允许我从普通的Instagram链接中获取媒体源(图像或视频),http://instagram.com/p/BUG/
无论用户是谁,也不需要access_token
.
简化示例:
var URL = "http://api.instagram.com/oembed?url=http://instagram.com/p/BUG/";
$(document).ready(function () {
$.ajax({
url: URL,
dataType: "jsonp",
cache: false,
success: function (response) {
console.log(response.url);
},
error: function () {
console.log("couldn't process the instagram url");
}
});
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,response.url
将返回完整的媒体URL源,如:
http://photos-a.ak.instagram.com/xxxx/1234_123456123_123456_n.jpg // image or
http://distilleryvesper3-15.ak.instagram.com/b0c957463548362858_101.mp4 // video
Run Code Online (Sandbox Code Playgroud)
然后我可以使用返回的URL将媒体文件嵌入我的网页.
注意:
由于想法是获取任何Instagram链接的URL源而不管用户,因此使用媒体端点不是一种选择.
Instagram的oembed端点允许您获得json
响应,直到最近几周才有这种结构:
{
"provider_url" : "http:\/\/instagram.com\/",
"media_id" : "123456789_123456789",
"title" : "the title",
"url" : "http:\/\/photos-a.ak.instagram.com\/hphotos-ak-xfp1\/12345678_123456789012345_1234567890_n.jpg",
"author_name" : …
Run Code Online (Sandbox Code Playgroud)