Home > Web Front-end > JS Tutorial > How to submit a request using JS using POST method (detailed answer combined with code)

How to submit a request using JS using POST method (detailed answer combined with code)

亚连
Release: 2018-05-18 10:36:06
Original
7520 people have browsed it

The following is the method I compiled for you to use JS to submit requests using POST method. Interested students can take a look.

Usually write hidden form tags, use To call the js function and then submit

You can also write it all in js. The following is an example I saw written by others in a question and answer channel. I put it here

function post(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;        
}             
//调用方法 如        
post('pages/statisticsJsp/excel.action', {html :prnhtml,cm1:'sdsddsd',cm2:'haha'});
Copy after login

The above is what I compiled I will give you a method of using JS to submit requests using POST method. I hope it will be helpful to you in the future.

Related articles:

How to implement printing in JS (detailed answer combined with code)

About in js Simple operation for downloading files (code attached, detailed answer)

# Questions about adding ! in front of function in js, the code is attached

The above is the detailed content of How to submit a request using JS using POST method (detailed answer combined with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template