模拟表单提交

function formSubmit(data) {
            var parames = new Array();
            parames.push({ name: "appId", value: data.appId});
            parames.push({ name: "phone", value: data.phone});
            parames.push({ name: "callbackUrl", value: data.callbackUrl});
            parames.push({ name: "userName", value: data.userName});
            parames.push({ name: "certificateNumber", value: data.certificateNumber});
            Post("http://testlottery.shixings.com/user/register", parames);//直接传去注册数据
            return false;
        }
        function Post(URL, PARAMTERS) {
            //创建form表单
            var temp_form = document.createElement("form");
            temp_form.action = URL;
            //如需打开新窗口,form的target属性要设置为'_blank'
            temp_form.target = "_self";
            temp_form.method = "post";
            temp_form.style.display = "none";
            //添加参数
            for (var item in PARAMTERS) {
                var opt = document.createElement("textarea");
                opt.name = PARAMTERS[item].name;
                opt.value = PARAMTERS[item].value;
                temp_form.appendChild(opt);
            }
            document.body.appendChild(temp_form);
            //提交数据
            temp_form.submit();
        }

你可能感兴趣的:(模拟表单提交)