码迷,mamicode.com
首页 > Web开发 > 详细

JS创建表单提交备份

时间:2017-06-07 14:16:51      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:doc   attr   com   htm   .post   action   txt   color   form   

 //保存
    function saveFT() {
      
        var data = {
            createDate: GetDateStr(0),
            name: $("#txtName").val(),
            gender: "未知",
            mobile: $("#txtTel").val(),
            email1: "null@null.com",
            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创建表单提交备份

标签:doc   attr   com   htm   .post   action   txt   color   form   

原文地址:http://www.cnblogs.com/CallmeYhz/p/6956278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!