$.ajax({
type: 'POST',
url: 'otherpage.php',
data: $('form').serialize(), //you may want to give id of the form which contains elements you want to POST
success: function(){
//code on success
},
dataType: 'html'
});
编辑1
如果你想指定你自己的参数发送然后使用:
$.ajax({
type: 'POST',
url: 'otherpage.php',
data: {
paramname1 : "put_param_value_here",
paramname2 : "put_param_value_here",
paramname3 : "put_param_value_here"
},
success: function(){
//code on success
},
dataType: 'html'
});
编辑2:如果您只想将自己的参数发布到页面(没有ajax。简单的POST将打开页面然后执行以下操作)
function postToUrl(url, params, newWindow)
{
var form = $('
');form.attr('action', url);
form.attr('method', 'POST');
if(newWindow){ form.attr('target', '_blank'); }
var addParam = function(paramName, paramValue){
var input = $('');
input.attr({ 'id': paramName,
'name': paramName,
'value': paramValue });
form.append(input);
};
// Params is an Array.
if(params instanceof Array){
for(var i=0; i
addParam(i, params[i]);
}
}
// Params is an Associative array or Object.
if(params instanceof Object){
for(var key in params){
addParam(key, params[key]);
}
}
// Submit the form, then remove it from the page
form.appendTo(document.body);
form.submit();
}像这样打电话: -
postToUrl('otherpage.php', {paramname1: "value_here", paramname2: "value_here"});代码取自JavaScript post request like a form submit上的答案