Can't sent addtional data(object) to backend while use jquery form plugin: ajaxSubmit

14 views Asked by At

As, title, can't pass object to backend, but simple string ("hihi" as below) is work.

I tried to use JSON.stringify(reportNameList) to let it become a string, but I still can't see it was passed to backend.

submitHandler: function(form) {
            $(form).ajaxSubmit(submitOptions);
        }


var submitOptions = {
        async: false,
        clearForm: false,
        resetForm:false,
        url: "/ReportEngine/saveALL",
        type: 'POST',
        data: {
            //"reportNameList": JSON.stringify(reportNameList),
            "reportNameList": "hihi",
        },
        success: function (data) {
            console.log(data);
        },
        beforeSend: showRequest,
        error: function (data) {
            console.log(data);
        }
    };

1

There are 1 answers

0
叶秀云Hanna On

It's because when var submitOptions is defined, reportNameList is not defined yet, so just write whole option in ajax() function, this problem is solved.