Native js implements form submission


I’m busy lately, so I’m in a hurry to get online. Write a simple thing. URL is the address you want to submit. Params is the parameter you submitted.

function fromPost(URL, PARAMS) {
    
    
                    var temp = document.createElement("form");
                    temp.action = URL;
                    temp.method = "post";
                    temp.style.display = "none";
                    for (var x in PARAMS) {
    
    
                        var opt = document.createElement("textarea");
                        opt.name = x;
                        opt.value = PARAMS[x];
                        // alert(opt.name)
                        temp.appendChild(opt);
                    }
                    document.body.appendChild(temp);
                    temp.submit();
                    return temp;
                }

Guess you like

Origin blog.csdn.net/lbchenxy/article/details/97932056