我正在使用来自Jquery ajax的Spring MVC调用。该呼叫命中控制器并在serever侧显示结果。但浏览器中没有显示我的代码
$.ajax({
url: "http://localhost:8080/sample/sample-byName",
cache: false,
data:'firstName=' + $("#firstName").val() + "&lastName=" + $("#lastName").val() + "¤tCompany=" + $("#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
答案 0 :(得分:0)
使用此代码
你错误地传递了值
值应该像这样传递
data: { name: "value", location: "value" }
$.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);
}
});