动态创建form 完成form 提交

    
document.body.appendChild(jForm) won't work because jForm is not a dom element, it is a jQuery object so add the below script before jForm.submit();

jForm.appendTo('body')
function loadPage(url, projectName) {
    var jForm = $('<form></form>', {
        action: url,
        method: 'post'
    });

    $("<input>", {
        name: 'curPrj',
        value: projectName
    }).appendTo(jForm);

    jForm.appendTo('body').submit();
}
 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);
    });
    form.appendTo('body').submit();

 

你可能感兴趣的:(动态创建form 完成form 提交)