简体   繁体   English

调用RESTful Web服务时jQuery getjson不起作用

[英]jquery getjson is not working when calling restful webservice

I'm trying to call a restful webservice from my jsp page. 我试图从我的jsp页面调用一个宁静的Web服务。

The restful web service is working fine and it is displaying the json data. 宁静的Web服务运行正常,并且正在显示json数据。 The problem is with the client. 问题出在客户端上。
The client is not able to get the web service data. 客户端无法获取Web服务数据。

I tried many ways but nothing worked. 我尝试了很多方法,但是没有任何效果。

This is the script: 这是脚本:

function getEmployeeDetails() {
    alert("Hai");
    alert($("#empid").val());
    $empid = $("#empid");
    alert("eval-->" + $empid.val());
    $.getJSON("http://localhost:8080/RestfulWS/restful/employee/" + $empid.val(), displayResult);

}

function displayResult(data) {
    alert("data" + data);

    $("#fname").val(data.firstName);
    $("#lname").val(data.lastName);
}​

and the HTML 和HTML

<form id="form1">
    <h2>Employee Details</h2>
    <table>
        <tr>
            <td>Employee ID : </td>
            <td><input type="text" id="empid" size="10"/> <input type="button"  value="Get Details" onclick="getEmployeeDetails()" /> </td>
        </tr>
        <tr>
            <td>FirstName : </td>
            <td><input type="text" id="fname" readonly size="30"/></td>
        </tr>
        <tr>
            <td>LastName :  </td>
            <td><input type="text" id="lname" readonly size="30"/></td>
        </tr>        
    </table>
</form>​

I am running the above code on tomcat with the port 19090. 我在上面的代码上使用端口19090在tomcat上运行。

Ok, Read HTTP access control , Cross-Origin Resource Sharing 好的,阅读HTTP访问控制跨域资源共享

and

How the origin is being determined 如何确定原点

To configure your controller to allow cross domain requests, 要将控制器配置为允许跨域请求,

This link will help 该链接将有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM