-1
我想獲得'http://localhost:8080/api/printer?exclude=temperature'[HTTP/1.1]提供的Json數據。如何從Restful API URL獲取JSON數據?
這是要提供的Json數據。
{
"state": {
"text": "Operational",
"flags": {
"operational": true,
"paused": false,
"printing": false,
"sdReady": true,
"error": false,
"ready": true,
"closedOrError": false
}
}
}
的類型是 'GET' 和Content-Type爲 '應用/ JSON的'
而且下面是我的JSP整個源代碼。
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" language="javascript">
function print_stat(){
jQuery.ajax({
type: 'GET',
async: false ,
url: 'http://localhost:8080/api/printer?exclude=temperature&apikey=1234567...',
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("TEST");
},
error : function(x, e) {
alert('server error occoured');
if(x.status==0){ alert('0 error');
}else if(x.status==404){ alert('404 error');
}else if(x.status==500){ alert('500 error');
}else if(e=='parsererror'){ alert('Error.nParsing JSON Request failed.');
}else if(e=='timeout'){ alert('Time out.');
}else { alert(x.responseText); }
}
});
}
</script>
<body>
<input type="button" onclick="print_stat()" value="test">
</body>
我看不到「TEST」彈出式窗口。 沒有任何反應。
我該如何獲取數據?
請幫幫我。
'異步:假的, '< - 主意不好 – epascarello
因此開發者控制檯中沒有錯誤? – epascarello
你包括jquery嗎?聽起來不像。 –