当我尝试从第二个网址获取数据时,我在firebug中收到错误,但是当我在评论中尝试网址时(第一个),一切正常,
function build()
{
$.ajax({
type: "GET",
contentType: "application/json",
crossDomain: true,
/// url: "http://localhost:9100/todo-0.1/data.json",
url:'localhost:9000/rest/admin/component?componentUri=file:/home/workspace/app/5-Integration/',
dataType: "json",
success: function (data)
{
var n=data.links.link[1]['@href'].indexOf("file");
var ContObject=new Object();
ContObject.data=new Object();
ContObject.data["title"]= decodeURI(data.links.link[1] ['@href'].substring(n));
ContObject.state="open";
ContObject.metadata=new Object();
ContObject.metadata["id"]= decodeURI(data.links.link[1]['@href'].substring(n));
var jsonText = JSON.stringify(ContObject);
var output="<div>";
output+= jsonText;
output+="</div>";
document.getElementById("placeholder").innerHTML=output;
alert("success");
},
error: function (data,status)
{
console.log("ERROR");
console.log(status);
}
});
感谢您的指导
答案 0 :(得分:2)
url:'localhost:9000/rest/admin/co....
必须是
url:'http://localhost:9000/rest/admin/co....
<强>更新强>
启用跨域请求:How to enable cross-domain request on the server?
调试:
success: function (data) { console.log(data); }