douchuifk90315 2013-11-05 19:42
浏览 246

使用jQuery .post()发送多个数组

I have looked and can't quite come up with an answer to this question. I currently have an array which I call dataArray. The dataArray contains 2 keys (name, value) and is set up like this:
dataArray.push({name : file.name, value : this.result});
I am passing this array to my PHP file using the .post() method like so:
$.post('upload.php', dataArray[index], function(data) {}.
Then in the upload.php file I retrieve the data using:

$file = $_POST['value'];
$name = $_POST['name'];

This works fine for what I need. My question is how do I pass and retrieve 2 separate arrays. I have another array called 'position' that I would also like to send using the .post() method. This array is set up like so:
position.push({left : 0, top : 0});
I can't seem to find a way to pass them both at the same time.

  • 写回答

2条回答 默认 最新

  • duan_2000 2013-11-05 19:54
    关注

    You can always pass an javascript object with 2 arrays in it...

    Like this:

    arrayData= {
        array1 = [],
        array2 = []
    };
    $.ajax({
        type: "POST",
        url: 'http://post.url',
        data: arrayData
    });
    

    Retrieve in php script like this:

    $arrayData = $_POST['arrayData'];
    foreach($arrayData as $value) {
        //$value['array1']
        //$value['array2']
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?