从Jsp获取数据到Ajax不起作用

时间:2015-05-24 17:54:59

标签: javascript ajax jsp

这甚至没有在调试

中输入服务器
$.ajax({
              type: 'GET',

              url: 'http://192.168.1.12:8080/HelpCenterService/api/db/getPatientsList',
              dataType: 'json',
               success: function (d) {
                   alert("good");
               },
               error: function () {
                   alert("bad");
               }
          });

这是在调试中进入服务器内部但我没有收到var aa

的任何数据
  var request = new XMLHttpRequest;
        request.open('GET', 'http://192.168.1.12:8080/HelpCenterService/api/db/getPatientsList', true);



        request.send(null);
        var aa = request.responseText;
        alert(aa);

如果我写了链接= http://192.168.1.12:8080/HelpCenterService/api/db/getPatientsList  进入铬的网址 我得到了

[{"tel":"01111111","address":"abc","birthDate":"11/11/1980","gender":1,"id":1,"firstName":"abc","lastName":"abc"}]

这是jsp服务器端

@Path("/getPatientsList") 
    @GET 
    @Produces(MediaType.APPLICATION_JSON) 
    public ArrayList<Patient> getPatientsList() throws Exception {

 //  a lot of funcs inside
        return pList; 
    }

1 个答案:

答案 0 :(得分:0)

If you'll open the console i think that you'll recive a messge like "Cross Origin Access Control Error", which means that if the issuer doesn't have a Domain name like the API server, the API server should be configed to publish jsons for the public, aka Cross Oigin Access "*".

you should read about it here: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

anyway, if you want to do it localy, you can refer the server as Localhost and then everything will be ok.