Javascript发送post请求

通过虚拟表单的形式提交post请求,从而实现页面的跳转

function httpPost(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];
        temp.appendChild(opt);
    }
document.body.appendChild(temp);
    temp.submit();
  
    return temp;

}

例子:

function exportIllegalData()  {

                                 var days = $(".days .hlg").attr("type");

if(days == undefined){
days = '';
}
var jobId ='';
var status = $(".status .hlg").attr("type");
if(status == undefined){
status = '';
}

var dateStartTime = $("#dateStartTime").datetimebox("getValue"); 

var dateEndTime = $("#dateEndTime").datetimebox("getValue"); 

var siteName = $("#siteName").val();
var contentType = $("#type").val();

var keyWords =$("#keyWords").val();

var params = {
"days":days,
"jobId":jobId,
"status":status,
"dateStartTime":dateStartTime,
"dateEndTime":dateEndTime,
"siteName":siteName,
"contentType":contentType,
"keyWords":keyWords
};
var httpUrl = "/illegal/task/exportAllData";
httpPost(httpUrl,params); 



你可能感兴趣的:(Javascript发送post请求)