0
尝试从GET服务获取响应时,ajax函数始终运行到错误部分。ajax从GET服务获取JSON字符串失败
<!DOCTYPE html>
<!-- jquery -->
<link rel="stylesheet" href="jquery/jquery-ui.css">
<script src="jquery/jquery-1.11.1.min.js"></script>
<script src="jquery/jquery-ui.js"></script>
<!-- bootstrap -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
$.ajax(
{
url: "http://localhost:8080/POC-WebApplication/obtenerusuarios",
type: "GET",
dataType: "jsonp",
success: function(data, textStatus, jqXHR)
{
alert("success");
},
error: function(data, textStatus, jqXHR)
{
alert("FAIL!!!!\ndata: "+data+"\ntextStatus: "+textStatus+"\njqXHR: "+jqXHR);
}
});
</script>
当浏览器执行我得到这个结果代码:
- 数据:[对象对象]
- textStatus:parserror
- jqXHR:错误:jQuery1111 ..... 3111不叫
我试图与数据类型: “JSON”,但我得到这个错误在Chrome调试控制台:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
和警报打印:
- 数据:[对象的对象]
- textStatus:错误
- jqXHR:错误:
**** **** EDITED
我解决了它使用这个Chrome应用:https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
我鼓励每个人都具有相同的问题,因为我使用它。
您使用的访问此文件是什么网址? – 2014-12-09 11:33:50
仅尝试将您的AJAX URL作为'/ POC-WebApplication/obtenerusuarios'。 – Shubh 2014-12-09 12:05:59