Javascript 如何使用jQuery Ajax.Request将多个变量类型传递给php
我需要向我的php页面传递一个数组和一个字符串。但我不知道该怎么做。这是我的密码: Javascript:Javascript 如何使用jQuery Ajax.Request将多个变量类型传递给php,javascript,php,jquery,Javascript,Php,Jquery,我需要向我的php页面传递一个数组和一个字符串。但我不知道该怎么做。这是我的密码: Javascript: function processData(myVar){ new Ajax.Request('myPage.php', { type: 'post', data: {myCmd: 'ProcessIt', addData: myVar}, onSuccess: function(transport) { return transport.re
function processData(myVar){
new Ajax.Request('myPage.php', {
type: 'post',
data: {myCmd: 'ProcessIt', addData: myVar},
onSuccess: function(transport) {
return transport.responseText;
}
});
}
<?php
if (empty($_POST)){
// $_POST is always empty. Even though the type is array.
}
PHP:
function processData(myVar){
new Ajax.Request('myPage.php', {
type: 'post',
data: {myCmd: 'ProcessIt', addData: myVar},
onSuccess: function(transport) {
return transport.responseText;
}
});
}
<?php
if (empty($_POST)){
// $_POST is always empty. Even though the type is array.
}
如果是html表单帖子,您可以这样做
[]
表示它作为数组发布 如果您想使用prototypejs发送帖子,这是ajax中的表单
new Ajax.Request('index/index.php', {
method: 'POST',
parameters: {
'options[]': JSON.stringify({"array1" : "option1", "array2" : "option2"}),
'option': "test"
},
onSuccess: function(transport){
console.log(transport);
}
});
我希望这对你有帮助
index.php
if(empty($_POST)){
echo "BAD";
}else{
echo json_encode($_POST);
}
什么是Ajax.Request
?我不记得jqueryIt中有这样的东西,它不是一个html表单POST>谢谢你,里卡多!这是一个巨大的帮助。