如何使用$ .ajax发布地图

时间:2015-05-11 08:29:45

标签: javascript jquery ajax spring

我有一个JS函数,应该在我的控制器中发布我需要的几个地图:

    var valuesOriginal = new Map();
    var valuesEdited = new Map();
    var valuesBackup = new Map();
    $.each($('#zgImport').serializeArray(), function(i, field) {

        if(field.name.substring(0,13) == "userLinesAuto"){
            valuesEdited.set(field.name, field.value);
        }else if (field.name.substring(0,17) == "userLinesOriginal"){
            valuesBackup.set(field.name, field.value);
        }else if (field.name.substring(0,9) == "userLines"){
            valuesOriginal.set(field.name, field.value);
        }

    });


$.ajax({

        type : 'POST',
        url : '<%= importAfterValidationUsers %>',
        data : { 
            original : valuesOriginal,
            edited : valuesEdited,
            backup : valuesBackup,
            formValidationSource : "original"
        },
        success: function(serverResponse) {
            alert("ok");
        },
        error: function () {
            alert("error");
        },
        timeout: 3000

    });

但在我的控制器中,我的地图始终为空

public void importAfterValidationUsers(ResourceRequest request, ResourceResponse response) throws IOException {

    Map<String, String[]> users =  request.getParameterMap();
    Map lala = request.getParameter("original");
}

request.getParameterMap()包含“formValidationSource”var但不包含map,request.getParameter(“original”)返回null。 我错过了什么?

1 个答案:

答案 0 :(得分:1)

变化:

formValidationSource : "original"

"original" : formValidationSource  

修改:尝试:

original : JSON.stringify(valuesOriginal)