dongluan6784 2010-08-03 02:02
浏览 43
已采纳

需要帮助$ .ajax函数 - 如何发送关联数组?

I would like to send data using $.ajax like this:

$.ajax({'url': 'my.php',
        'type': 'POST',
        'data': arr,
        'success': function(response) {
                      alert(response);
                   }
});

The problem is that arr is an associative array that looks like:

arr['description_0'] = 'very nice picture!';
arr['tags_0'] = 'David "Nice Picture" 2010';
arr['description_1'] = 'In the pool';
arr['tags_1'] = '"April 2010" Australia';
    .                    .
    .                    .
    .                    .

If my.php looks like:

<?php
echo count($_POST);
?>

The response is 0.

But, if I change

'data': arr,

to

'data': 'a=chess&b=checkers',

the response is 2, as expected.

What should I convert arr to so that the data will be sent properly ?

  • 写回答

4条回答 默认 最新

  • doujiebo9849 2010-08-03 02:14
    关注

    if you're really having problems on that, try reading $.param().


    also, I've discovered, how did you initialize your arr variable?

    you should initialize it as var arr = {}; then pass it as 'data': arr,. Try to look at firebug or webket's dev tools to see what data are being posted to the server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)