响应法规200可以,但使用jquery错误功能

时间:2013-11-03 16:37:05

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

我创建了一个restfull Web服务,它返回一个json结果和URL: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.

可能是什么问题?

1 个答案:

答案 0 :(得分: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      
});   
相关问题