我試圖做一個從jquery到休息服務的ajax調用。其餘服務使用的是從mkyong的博客教程,這一個:http://www.mkyong.com/webservices/jax-rs/integrate-jackson-with-resteasy/jQuery ajax調用REST服務
該服務的工作原理,但是當我嘗試從jQuery調用,在Firebug中有200狀態碼,但在響應部分, 沒有。
這裏是Ajax調用的html頁面:
<html>
<head>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
</head>
<body>
<button id="ajax">ajax call</button>
<button id="json">json</button>
<script type="text/javascript">
$('#json').click(function(){
alert('json');
$.getJSON("http://localhost:8080/restws/json/product/get",
function(data) {
alert(data);
});
});
$('#ajax').click(function(){
alert('ajax');
$.ajax({
type: "GET",
dataType: "json",
url: "http://localhost:8080/restws/json/product/get",
success: function(data){
alert(data);
}
});
});
</script>
</body>
</html>
我無法弄清楚哪裏出了問題,你能告訴我什麼,我做錯了什麼?
謝謝!
是您的網站上'HTTP運行://本地主機:8080'呢?如果不是('http:// localhost /'是[* not * the same](http://en.wikipedia.org/wiki/Same_origin_policy)),那麼您必須使您的API輸出[JSONP]( http://en.wikipedia.org/wiki/JSONP)。 –
不,這只是一個簡單的html,它是雙擊運行的:D – DaJackal
我的意思是,指向此頁面的URL是什麼? –