js跳转传递php参数,将JS / Jquery中的参数传递到另一页上的PHP
$.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。簡單的P??OST將打開頁面然后執行以下操作)
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上的答案
總結
以上是生活随笔為你收集整理的js跳转传递php参数,将JS / Jquery中的参数传递到另一页上的PHP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 读《java的讲座》后感,老师讲座听后感
- 下一篇: 基于jquery的php分页,基于jQu