【发布时间】:2016-09-09 17:52:06
【问题描述】:
您好,我有这段代码可以从 index.html 加载页面:
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
<script>
function jsonCallback(json){
console.log(json);
alert(document.cookie.json)
}
$.ajax({
url: "https://run.plnkr.co/plunks/v8xyYN64V4nqCshgjKms/data-2.json",
dataType: "jsonp"
});
</script>
我想要获取 cookie,所以在 https://run.plnkr.co/plunks/v8xyYN64V4nqCshgjKms/data-2.json 我已经在控制台中执行:document.cookie='test=123' 并返回未定义。为什么?我该如何解决?
这是该 URL 返回的内容:
jsonCallback(
{
"sites":
[
{
"siteName": "SitePoint",
"domainName": "https://www.sitepoint.com",
"description": "SitePoint is a hub for web developers to share their passion for building incredible Internet things."
},
{
"siteName": "A List Apart",
"domainName": "http://alistapart.com/",
"description": "A List Apart explores the design, development, and meaning of web content, with a special focus on web standards and best practices."
},
{
"siteName": "Smashing Magazine",
"domainName": "https://www.smashingmagazine.com/",
"description": "Smashing Magazine delivers useful and innovative information to Web designers and developers."
}
]
}
);
【问题讨论】:
标签: javascript jquery json jsonp