私はAjaxを初めて使用します。コントローラーメソッドを呼び出そうとしていますが、与えられたURLを呼び出さずにAjaxから呼び出します。ここでは、コントローラーメソッドとajax呼び出しをjspファイルで呼び出します。
@RequestMapping(value = "/getdata", method = RequestMethod.POST)
public @ResponseBody String add(@RequestParam(value="userDetailObject", required=true) User_Details u,Model model) {
System.out.println("In the controller method..");
String result=null;
result="From controller :"+u.getEmail();
System.out.println("at controller .."+result);
return result;
}
そして私のAjaxは
//script type="text/javascript" src="../jquery-1.4.4.js"
var jq = jQuery.noConflict();
function getData() {
alert("hello");
// get the form values
var email = $('#email').val();
// var education = $('#education').val();
$.ajax({
type : 'POST',
dataType: 'json',
url : "/SpringDemoSts/getdata",
data : 'email=' + email,
success : function(response) {
// we have the response
//$('#info').html(response);
$('#email').val(response);
//$('#education').val('');
},
error : function(e) {
alert('Error: ' + e);
}
});
}
/script
何が悪いのか私はここで間違っているのですか?