`

js使用post请求

阅读更多

一般都是写上隐藏的fomr标签,用<a href="#" onclick="..."/>来调用js函数然后submit

全部用js来写也行,以下是我在一个问答频道看见别人写的例子,放在这里

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'});

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics