Post 提交跳转页面 Jquery请求

使用场景,自定义参数进行post 提交跳转

参考于:https://blog.csdn.net/xxmeng2012/article/details/51489072/

使用参考文章方法,报警告

Form submission canceled because the form is not connected

翻译意思:表单提交已取消,因为该表单未连接

主要是用js构造表单时出现的问题,原因是没有把 form 放置到 body中

所以需要加上

$(“body”).append(form);

总结后方法,如下:

Jquery 扩展方法

//post 跳转扩展方法
    $.extend({
        StandardPost: function (url, args) {
            var form = $("<form method='post'></form>"),
                input;
            form.attr({ "action": url });
            $.each(args, function (key, value) {
                input = $("<input type='hidden'>");
                input.attr({"name": key });
                input.val(value);
                form.append(input);//参考文章中没有此句,提交会被拒绝--表单提交已取消,因为该表单未连接
            });
            $("body").append(form);
            form.submit();
        }
    });

 使用

$.StandardPost('/i/cartindex/settlement', { ids: ids });
原文地址:https://www.cnblogs.com/dyd520/p/14501244.html