Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jQuery Ajax.Request将多个变量类型传递给php_Javascript_Php_Jquery - Fatal编程技术网

Javascript 如何使用jQuery Ajax.Request将多个变量类型传递给php

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

我需要向我的php页面传递一个数组和一个字符串。但我不知道该怎么做。这是我的密码:

Javascript:

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>谢谢你,里卡多!这是一个巨大的帮助。