2013-07-10 80 views
1

嗨,我開發了一個基於球衣1.8寧靜的Web服務。 當我從瀏覽器中調用webservice的類似 http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808我有輸出像無法從jquery調用jersey webservice?

{"name":"Aneel Kumar Ravula","pollingStationLocation":"MARRIPALLI MPP SCHOOL","gender":"male","age":23,} 

但是,當我從失敗的jQuery Ajax和控制研究,在調用誤差函數。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<TITLE> New Document </TITLE> 
<META NAME="Generator" CONTENT="EditPlus"> 
<META NAME="Author" CONTENT=""> 
<META NAME="Keywords" CONTENT=""> 
<META NAME="Description" CONTENT=""> 
<script> 


$(document).ready(function() { 
      // fetch some more records from the server side 
      $.ajax({ 
       type: "GET", 
       contentType: "json", 
       url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808", 
       success: function(){alert('sucess by anil')}, 
       error: function(event){alert('fail by anilevent '+event)} 
      }); 

    }); 
</script> 
</HEAD> 

<BODY> 
</BODY> 
</HTML> 

現在這是我最新的代碼如何獲得響應

$(document).ready(function() { 
jQuery.support.cors = true; 
      // fetch some more records from the server side 
      $.ajax({ 
       type: "GET", 
       dataType : "JSON", 
       url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808", 
       crossDomain : true , 
       success: function(resp){alert('sucess by anil'+resp)}, 
       error: function(jqXHR, testStatus, errorThrown){alert('fail by anilevent '+errorThrown)} 
      }); 

    }); 
+0

你真的需要跨域:真正的本地主機? – Dodecapus

+0

實際上不是neede,但我嘗試了不同的選項忘記刪除 – AnilHoney

+0

取出contentType或將其更改爲dataType – Dodecapus

回答

2

這就是我想你的Ajax調用應該像

$(document).ready(function() { 
     jQuery.support.cors = true; 

     // fetch some more records from the server side 
     $.ajax({ 
      type: "GET", 
      dataType: "json", 
      url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808", 
      success: function(data){alert('sucess by anil: ' + data.name)}, 
      error: function(jqXHR, textStatus, errorThrown){alert('fail by anilevent '+errorThrown)} 
     }); 

}); 
+0

無法通過anilevent沒有運輸這是我得到你的代碼 – AnilHoney

+0

嘗試添加jQuery.support.cors = true;更新後。 – Dodecapus

+0

resp是[object objeect]如何獲取數據 – AnilHoney