JS创建表单提交备份

Posted 坚持不懈,才能出彩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS创建表单提交备份相关的知识,希望对你有一定的参考价值。

 //保存
    function saveFT() {
      
        var data = {
            createDate: GetDateStr(0),
            name: $("#txtName").val(),
            gender: "未知",
            mobile: $("#txtTel").val(),
            email1: "[email protected]",
            interested:$("#C2 option:selected").text(),
            buyCarTime: "有购车计划但没决定时间",
            province: $("#A2 option:selected").text(),
            city: $("#A3 option:selected").text(),
            dealerName: $("#ddlDealer option:selected").text(),
            eventCode: "1491550852610",
            memo1: "2017年DAF南区3-4月促销计划",
            memo2: "http://design.haoche.cn/haoche/2017/4/7/fute/index.html",
            source: ‘好车网_PC‘
        }

        var turnForm = document.createElement("form");
        //一定要加入到body中!!
        document.body.appendChild(turnForm);
        turnForm.method = ‘post‘;
        turnForm.acceptCharset = "UTF-8";
        turnForm.action = ‘http://www.changanfordclub.com/Media2Ford/json/CommitData.action‘;
        turnForm.target = ‘login2‘;
        turnForm.enctype = "text/json; charset=UTF-8";


        //创建隐藏表单
        var newElement = document.createElement("input");
        newElement.setAttribute("name", "createDate");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.createDate);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "name");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.name);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "gender");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.gender);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "mobile");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.mobile);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "email1");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.email1);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "interested");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.interested);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "buyCarTime");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.buyCarTime);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "province");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.province);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "city");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.city);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "dealerName");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.dealerName);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "eventCode");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.eventCode);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "memo1");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.memo1);
        turnForm.appendChild(newElement);

        newElement = document.createElement("input");
        newElement.setAttribute("name", "memo2");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.memo2);
        turnForm.appendChild(newElement);


        //新添加Source
        newElement = document.createElement("input");
        newElement.setAttribute("name", "source");
        newElement.setAttribute("type", "hidden");
        newElement.setAttribute("value", data.source);
        turnForm.appendChild(newElement);

        turnForm.submit();

        //   $.post(
        //     "http://www.changanfordclub.com/Media2Ford/json/CommitData.action",
        //     data,
        //     "json",
        //    function (data) {
        //        if (data.success) {

        //        }
        //    }
        //);
        //$.ajax({
        //    type: "POST",
        //    url: "http://www.changanfordclub.com/Media2Ford/json/CommitData.action",
        //    data: data,
        //    dataType: "html",
        //    cache: false,

        //    success: function (data) {
        //    }
        //});
    }

 

以上是关于JS创建表单提交备份的主要内容,如果未能解决你的问题,请参考以下文章

为 Laravel 集体表单创建手动提交按钮

ajaxFileUpload上传带参数文件及JS验证文件大小

使用 parsley.js 验证表单提交外部表单标记

SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段

使用浏览器地址栏中编写的 JS 代码自动提交表单的问题

js创建表单并提交