0

我正在使用来自 Jquery ajax 的 Spring MVC 调用。呼叫击中控制器并在服务器端显示结果。但是浏览器中没有显示我的代码

$.ajax({
        url: "http://localhost:8080/sample/sample-byName",
        cache: false,               
         data:'firstName=' + $("#firstName").val() + "&lastName=" + $("#lastName").val() + "&currentCompany=" + $("#currentCompany").val(),
         dataType:"text",
         crossDomain : true,
         ContentType:"text/html",
        success: function(data){
            alert(data);
        },
        error: function(e){                     
            alert('Error while request..'+e);
        }
    });

当我看穿萤火虫时,它说200 OK。有人可以帮我吗?

我的控制器代码是

 public @ResponseBody String getLinkedInByName(HttpServletRequest request) {

       String firstName = request.getParameter("firstName");
       String lastName = request.getParameter("lastName");
       String currentCompany = request.getParameter("currentCompany");


        String resultJson = client.getNameSearchWithHelpers(firstName,lastName,currentCompany);
        System.out.println(resultJson);
        return resultJson;
    }

通过 Ajax 获得的净结果 Allow GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH Content-Length 0 Date Tue, 16 Jul 2013 05:17:18 GMT Server Apache-Coyote/1.1

普通网址提交 Content-Length 640 Content-Type text/html Date Tue, 16 Jul 2013 05:14:21 GMT Server Apache-Coyote/1.1

4

1 回答 1

0

使用此代码

你在传递值时犯了错误

值应该像这样传递

data: { name: "value", location: "value" }  

JS

$.ajax({
    url: "http://localhost:8080/sample/sample-byName",
    cache: false,               
    data:{firstName:$("#firstName").val() 
        ,lastName:$("#lastName").val(),
        currentCompany:$("#currentCompany").val()
    },
    dataType:"text",
    crossDomain : true,
    ContentType:"text/html",
    success: function(data){
    alert(data);
    },
    error: function(e){                     
    alert('Error while request..'+e);
    }
});
于 2013-07-16T04:57:50.777 回答