【发布时间】:2013-12-25 13:41:20
【问题描述】:
有一个这样的对象数组:
rectangle[0].width = w;
rectangle[0].height = h;
rectangle[1].width = w;
rectangle[2].height = h;
rectangle[3].width = w;
rectangle[3].height = h;
...
我们如何通过 jQuery.ajax 请求将此数组发送到 PHP 函数,反之亦然,从 PHP 函数修改数组作为响应? 我介意JS代码可能是:
request = $.ajax({
type : "POST",
url : "post.php",
data : {rec :rectangle}
});
request.done(function(msg) {
alert(msg);
});
request.fail(function(jqXHR, textStatus) {
alert("Function inaccessible: " + textStatus)
});
和 PHP:
if (isset($_POST["rec"]) {
$rec = $_POST["rec"];
$arr_length = count($rec);
$response = $arr_length;
}
echo $response;
请展示请求的真实形式。谢谢。
【问题讨论】:
-
你卡在哪里了?检查任何关于如何使用 ajax 发送数据的教程...
-
建设性评论!第一次询问并立即打卡:(
标签: javascript php jquery ajax arrays