405 not allowed

今天写了一个ajax post application的请求函数如下

function telnetTest(obj, url, x1, x2) {
        console.log(url);
        console.log(x1);
        console.log(x2);
        layer.confirm('Confirm to telnet?', {btn: ['Yes', 'Canal'], title: "Tips"}, function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                data: {
                    'x1':x1,
                    'x2':x2
                },
                contentType: 'application/json',
                dataType: 'json',
                success: function (data) {
                    if (data.resultCode == "200") {
                        layer.msg(data.resultMsg, {icon: 3, time: 3000});
                    }
                    else {
                        layer.msg(data.resultMsg, {icon: 4, time: 4000});
                    }
                },
                error: function (data) {
                    console.log("exception:" + data);
                }
            });
        });
    }

后来改成了如下就可以了

function telnetTest(obj, url, x1, x2) {
        console.log(url);
        console.log(x1);
        console.log(x2);
        var params = {
                'x1':x1,
                'x2':x2
            };
        layer.confirm('Confirm to telnet?', {btn: ['Yes', 'Canal'], title: "Tips"}, function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                data: JSON.stringify(params),
                contentType: 'application/json',
                dataType: 'json',
                success: function (data) {
                    if (data.resultCode == "200") {
                        layer.msg(data.resultMsg, {icon: 3, time: 3000});
                    }
                    else {
                        layer.msg(data.resultMsg, {icon: 4, time: 4000});
                    }
                },
                error: function (data) {
                    console.log("exception:" + data);
                }
            });
        });
    }

后端controller

    @RequestMapping(value = "/telnet/test", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String telnetTest(@RequestBody Map map) {

 

你可能感兴趣的:(前端)