【发布时间】:2015-06-25 00:41:05
【问题描述】:
我的目标是获取 Http“Get”的 json 输出。然后使用这个 json 输出到 D3。
我创建了一个如下的httpGet函数,设置和我的Postman完全一样,我可以在Postman中得到json响应。
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, true, "admin", "admin" );
xmlHttp.setRequestHeader('Content-Type', 'application/json');
xmlHttp.setRequestHeader('X-M2M-Origin', '//localhost:10000');
xmlHttp.setRequestHeader('X-M2M-RI', '12345');
xmlHttp.setRequestHeader('X-M2M-OT', 'NOW');
xmlHttp.send();
return "[" + xmlHttp.responseText + "]";
}
var aaa = httpGet('localhost:8282/InCSE1/?rcn=4');
它们在同一个域中。在 javascript 中,chrome 告诉我:
选项 /localhost:8282/InCSE1/?rcn=4 httpGet @ (index):118update @ (索引):105(匿名函数)@(索引):61t @ d3.v3.min.js:1(匿名函数)@d3.v3.min.js:1t@d3.v3.min.js:1u @d3.v3.min.js:1 (index):1 XMLHttpRequest 无法加载 http://localhost:8282/InCSE1/?rcn=4。 HTTP 状态码 500 无效!
【问题讨论】:
标签: javascript json xmlhttprequest