【发布时间】:2013-08-20 19:35:54
【问题描述】:
我已经开始学习javascript,我在下面写了一段代码。
var dataFetch = $.getJSON("http://localhost:12345/stream", function (Data) {
alert(Data);
$.each( Data, function () {
alert(this);
$("<li>").html(this.rss).prependTo(tweetList);
});
});
dataFetch.done(function () {
alert("done");
});
dataFetch.fail(function () {
alert("fail");
});
当我将链接 http://localhost:12345/stream 放入浏览器时,我得到:
{"rss":{"version":"2.0","channel":{"title":"Dave Winer","link":"http://scripting.com/","description":"Dave Winer's \"Scripting News\" weblog, started in April 1997, bootstrapped the blogging revolution.","language":"en-us","copyright":"Copyright 2012 Scripting News, Inc.","pubDate":"Mon, 08 Oct 2012 04:00:00 GMT","lastBuildDate":"Mon, 08 Oct 2012 18:12:27....
........... much more here
但是当我运行这个 html 文件时,我得到 failure with alert 对话框的失败。
我通过 JSON.stringify(some_json_object). 从 node.js 服务器代码在本地主机上发送数据。
什么是错误?
【问题讨论】:
-
打开控制台查看错误
-
你是否在你的nodejs服务器'Access-Control-Allow-Origin: *'中添加了这个头文件??这可能是 CORS 问题..
-
尝试修改你的回调为 dataFetch.fail(function (error) { alert("Error is " + error); });
-
@iBlue。这表明错误是[对象]?有什么链接 error.msg 吗?
-
我认为 CORS 有效。感谢伟大的丹顿
标签: javascript jquery json node.js