jquery模拟form表单提交并新打开页面

/**
 * form表单提交本页面打开
 * @param url
 * @param params
 */
function postCurrent(url,params){
    var form = $("<form method='post'></form>");
    var input;
    form.attr({"action":url});
    $.each(params,function (key,value) {
        input = $("<input type='hidden'>");
        input.attr({"name":key});
        input.val(value);
        form.append(input);
    });
    $(document.body).append(form);
    form.submit();
}

 

/**
 * form表单提交新打开页面
 * @param url
 * @param params
 *@windowname
 */
function postNew(url,params,windowname){
    var form = $("<form method='post'></form>");
    var input;
    form.attr({"action":url});
    $.each(params,function (key,value) {
        input = $("<input type='hidden'>");
        input.attr({"name":key});
        input.val(value);
        form.append(input);
    });
    form.attr({"target":windowname});
    window.addEventListener("onsubmit",function(){ openWindow(windowname); });
    $(document.body).append(form);
    window.dispatchEvent(new Event("onsubmit"))
    form.submit();
}

function openWindow(name)
{
    window.open('about:blank',name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
}

 

        //调用    
        preview(){
                        var json = {
                       'workStatus': workStatus,
                       'designNums': this.designNums,
                       'designModel': this.designModel,
                       'worksType': this.worksInfo.worksType,
                       'designUserList': JSON.stringify(designUserList),
                       'promiseImg1': this.promiseImg1,
                       'promiseImg2': this.promiseImg2,
                       'promiseImg3': this.promiseImg3,
                       'promiseImg4': this.promiseImg4,
                       'worksInfo': JSON.stringify(worksInfo)
                   };
                   let postUrl = [[@{/design/showPreviewHtml}]];
                   postCurrent(postUrl,json);
               },   

 

posted @ 2018-06-29 09:59 SimonHu1993 阅读(...) 评论(...) 编辑 收藏
Flag Counter