【问题标题】:Response statut 200 is OK but use jquery error function响应状态 200 可以,但使用 jquery 错误函数
【发布时间】:2013-11-03 16:37:05
【问题描述】:

我创建了一个返回 json 结果和 URL 的 restfull 网络服务:myURL/annonces/contract/sepcifiedContract/1 返回此结果:

{"contractId":1,"labelContract":"INFO"}

这是我获取数据的脚本:

<script>

$(document).ready(function(){
    $.ajax({
        url: "http://127.0.0.1:8080/NoticeManagerServer/annonces/contract/sepcifiedContract/1",
        type: "GET",
        dataType: 'json',
        success: render,
        error: errorf,
        failure: failf      
    });         
});
function render(){
$("p").append("success function."); 
}
function failf(){
 $("p").append(" failure faunction."); 
}
function errorf(){
$("p").append("error function."); 
}
</script>

html结果是:

 error function.

可能是什么问题?

【问题讨论】:

  • 错误函数接收状态参数,为什么不显示出来看看原因?
  • 状态显示“错误”。
  • 参数错误显示:异常...“访问受限URI被拒绝”代码:“1012”nsresult:“0x805303f4(NS_ERROR_DOM_BAD_URI)”位置:“ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js Line:6”]跨度>
  • 您遇到了 AJAX 同源策略。 URL 必须与您正在运行 AJAX 调用的页面具有相同的域和端口号。
  • 是的,这是因为我编辑了网址,但现在它显示:[异常...“失败”nsresult:“0x80004005(NS_ERROR_FAILURE)”位置:“JS 框架 :: file:///D: /workspace/workspaceAndroid/FirstApp/assets/www/js/jquery-1.10.2.min.js :: .send :: line 6" data: no]

标签: jquery json web-services http-headers jersey


【解决方案1】:

这可能是一个跨域问题。 试试看:crossDomain: true

这样写:

$.ajax({
    url: "http://127.0.0.1:8080/NoticeManagerServer/annonces/contract/sepcifiedContract/1",
    type: "GET",
    dataType: 'json',
    crossDomain: true,
    success: render,
    error: errorf,
    failure: failf      
});   

【讨论】:

  • 这不能解决问题,它仍然给我“错误功能”
  • 该选项不会禁用同源策略。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-21
  • 1970-01-01
  • 2017-12-15
  • 2015-09-30
  • 2021-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多