您好我开发了一个基于1.8平静的球衣服务。
当我从浏览器调用webservice时
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)}
});
});
答案 0 :(得分: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)}
});
});