dongluan6784
dongluan6784
2010-08-03 02:02

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

  • php
  • ajax
  • javascript
  • jquery

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条回答

为你推荐