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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog