为什么我不能用Jquery传递一个简单的数组

时间:2018-04-27 14:26:44

标签: javascript java jquery spring

我有一些简单的代码,我正在

  

HTTP状态400 - 错误请求   输入状态报告

     

消息必需String []参数'testCaseNames'不存在

当使用chrome开发人员工具显然位于formData部分时。

flowName: gsaasggsa
params[]: QUERY=select 1 from cuvar
params[]: PASSWORD=xasf
params[]: USERNAME={{ 0.OUTPUT }}
params[]: PASSWORD=xxx
params[]: USERNAME={{ 0.OUTPUT }}
testCaseNames[]: sql_test
testCaseNames[]: test_loginFail
testCaseNames[]: test_loginSuccess

我在这里缺少什么?为什么我不能通过它?

$.ajax({
    type: 'post',
    url: "/flow/import",
    data: {
        linkageObject: linkageObject,
        flowName: flowName,
        params: params,
        testCaseNames: testCaseNames
    },
    success: function() {
        new PNotify({
            title: 'Flow Creation',
            text: 'Flow was imported successfully. It is available for use',
            type: 'success'
        });
        location.href = "/execute-flow";
    }
});

控制器

@RequestMapping(value = "/flow/import" , method = RequestMethod.POST
public @ResponseBody String importFlow(
    HttpSession session,
    @RequestParam("flowName") String flowName,
    @RequestParam("testCaseNames") String[] testCaseNames,
    @RequestParam(value = "params", required = false) String[] params,
    @RequestParam(value = "linkageObject", required = false) String linkageObject) { 

}

编辑:我没有放置linkageObject。

linkageObject=%22%7B%5C%22operators%5C%22%3A%7B%5C%22operator0%5C%22%3A%7B%5C%22top%5C%22%3A160%2C%5C%22left%5C%22%3A640%2C%5C%22properties%5C%22%3A%7B%5C%22title%5C%22%3A%5C%22sql_test+(SQL)%5C%22%2C%5C%22inputs%5C%22%3A%7B%5C%22input_0%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22QUERY%5C%22%7D%7D%2C%5C%22outputs%5C%22%3A%7B%5C%22output_0%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22OUTPUT%5C%22%7D%7D%7D%7D%2C%5C%22operator1%5C%22%3A%7B%5C%22top%5C%22%3A260%2C%5C%22left%5C%22%3A920%2C%5C%22properties%5C%22%3A%7B%5C%22title%5C%22%3A%5C%22test_loginFail+(CSR)%5C%22%2C%5C%22inputs%5C%22%3A%7B%5C%22input_0%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22USERNAME%5C%22%7D%2C%5C%22input_1%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22PASSWORD%5C%22%7D%7D%2C%5C%22outputs%5C%22%3A%7B%7D%7D%7D%2C%5C%22operator2%5C%22%3A%7B%5C%22top%5C%22%3A100%2C%5C%22left%5C%22%3A920%2C%5C%22properties%5C%22%3A%7B%5C%22title%5C%22%3A%5C%22test_loginSuccess+(CSR)%5C%22%2C%5C%22inputs%5C%22%3A%7B%5C%22input_0%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22USERNAME%5C%22%7D%2C%5C%22input_1%5C%22%3A%7B%5C%22label%5C%22%3A%5C%22PASSWORD%5C%22%7D%7D%2C%5C%22outputs%5C%22%3A%7B%7D%7D%7D%7D%2C%5C%22links%5C%22%3A%7B%5C%221%5C%22%3A%7B%5C%22fromOperator%5C%22%3A%5C%22operator0%5C%22%2C%5C%22fromConnector%5C%22%3A%5C%22output_0%5C%22%2C%5C%22fromSubConnector%5C%22%3A0%2C%5C%22toOperator%5C%22%3A%5C%22operator2%5C%22%2C%5C%22toConnector%5C%22%3A%5C%22input_0%5C%22%2C%5C%22toSubConnector%5C%22%3A0%7D%2C%5C%222%5C%22%3A%7B%5C%22fromOperator%5C%22%3A%5C%22operator0%5C%22%2C%5C%22fromConnector%5C%22%3A%5C%22output_0%5C%22%2C%5C%22fromSubConnector%5C%22%3A0%2C%5C%22toOperator%5C%22%3A%5C%22operator1%5C%22%2C%5C%22toConnector%5C%22%3A%5C%22input_0%5C%22%2C%5C%22toSubConnector%5C%22%3A0%7D%7D%2C%5C%22operatorTypes%5C%22%3A%7B%7D%7D%22&flowName=gsaasggsa&params%5B%5D=QUERY%3Dselect+1+from+cuvar&params%5B%5D=PASSWORD%3Dxasf&params%5B%5D=USERNAME%3D%7B%7B+0.OUTPUT+%7D%7D&params%5B%5D=PASSWORD%3Dxxx&params%5B%5D=USERNAME%3D%7B%7B+0.OUTPUT+%7D%7D&testCaseNames%5B%5D=sql_test&testCaseNames%5B%5D=test_loginFail&testCaseNames%5B%5D=test_loginSuccess

完整代码:

var reader = new FileReader();

reader.onload = function(event) {
    var jsonObject = JSON.parse(event.target.result);
    var testCaseNames = [],
        params = [];
    var linkageObject = null;
    $.each(jsonObject, function(index, testCase) {
        console.log(testCase);
        if (testCase.hasOwnProperty("linkageObject")) {
            linkageObject = JSON.stringify(testCase.linkageObject);
        } else {
            var testCaseName = testCase.name.split("/")[1].split('.')[0];
            testCaseNames.push(testCaseName);
            $.each(testCase.inputs, function(k, v) {
                params.push(k + "=" + v);
            });
        }
    });

    $.ajax({
        type: 'post',
        url: "/flow/import",
        //url: '/flow/import?flowName=' + flowName + "&testCaseNames=" + testCaseNames + "&params=" + params,
        data: {
            linkageObject: linkageObject,
            flowName: flowName,
            params: params,
            testCaseNames: testCaseNames
        },
        success: function() {
            new PNotify({
                title: 'Flow Creation',
                text: 'Flow was imported successfully. It is available for use',
                type: 'success'
            });
            location.href = "/execute-flow";
        }
    });
};
reader.readAsText(file);
}

0 个答案:

没有答案