0

私は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

何が悪いのか私はここで間違っているのですか?

4

1 に答える 1

0

ajax で定義された URL:

/SpringDemoSts/getdata

示されているリクエストマッピングのそれとは異なります

/getdata

パラメータはuserDetailObjectと呼ばれ、ajax呼び出しでデータが正しく定義されていない場合、リクエストパラメータスタイルをデータとして使用しています。実際にjson/プレーンプリミティブまたは文字列が必要な場合。

于 2013-03-01T12:47:22.870 に答える