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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题