こんにちは、jersey 1.8 restful に基づく Web サービスを開発しました。ブラウザからWebサービスを呼び出すと、次のような
http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808
出力が得られました
{"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)}
});
});