我正在使用freetexthost.com存储我的json代码。现在,我必须使用javascript、jquery、ajax从url获取这些内容……bt我无法得到它..我尝试了下面的代码
<!DOCTYPE html>
<html>
<head>
<title>Useless</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
<script type="text/javascript">
$.ajax({
type: "GET",
url: "http://freetexthost.com/r56ct5aw03",
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
</script>
</head>
<body>
<div class="content" >Hello</div>
</body>
</html>
获取一个错误,因为` `Uncaught :意外的标记<
有没有可能我们可以使用js操作其他页面(Url)的内容…
发布于 2014-02-24 18:11:20
您需要使用"
关闭您的url
$.ajax({
type: "GET",
url: "https://http://freetexthost.com/r56ct5aw03", // <-- Here
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
发布于 2014-02-24 18:13:32
页面http://freetexthost.com/r56ct5aw03的内容是html,应该是jsonp才能正确解析。
json和jsonp之间的唯一区别是,当调用jsonp时,您还将传递回调参数
e.g. url:"http://freetexthost.com/r56ct5aw03?callback=myFunction",
现在,服务器端应该打印这个函数名中包含的json,如下所示。
myFunction(
{
"sites":
[
{
"siteName": "123",
"domainName": "http://www.123.com",
"description": "123"
},
{
"siteName": "asd",
"domainName": "http://www.asd.com",
"description": "asd"
},
{
"siteName": "zxc",
"domainName": "http://www.zxc.com",
"description": "zxc"
}
]
}
);
https://stackoverflow.com/questions/21984576
复制相似问题