【发布时间】:2014-04-30 16:18:08
【问题描述】:
我正在尝试从 000webhost 上的主机获取数据
数据是一个 JSONP 文件:
{
"categories": {
"category": [
{
"name": "Android",
"parent": "Computer Science",
"ID": "2323"
},
{
"name": "Java",
"parent": "Android",
"ID": "12"
},
{
"name": "HTML",
"parent": "Android",
"ID": "32"
},
{
"name": "Javascript",
"parent": "Android",
"ID": "4552"
},
{
"name": "CSS",
"parent": "Android",
"ID": "4553"
},
{
"name": "Math",
"parent": "Computer Science",
"ID": "3778342"
},
{
"name": "JAVA",
"parent": "Computer Science",
"ID": "377655"
},
{
"name": "Computer Science",
"parent": "none",
"ID": "1"
}
]
}
}
我试过了:
$(document).ready(function(){
(mainFunction=function(){
$.ajax({
dataType: 'jsonp',
data: null,
jsonp: 'categories',
url: 'http://blabla.site11.com',
success: function (response) {
}
});
})();
但我总是收到错误:Uncaught SyntaxError: Unexpected token.
我只是想知道如何从http://blabla.site11.com/categories.jsonp 获取 categories.jsonp 文件
【问题讨论】:
-
听起来服务器不处理 jsonp
-
你知道,JSONP 需要服务器在 JSON 周围添加一个 JS 函数调用?
标签: javascript jquery ajax json