用jquery用post传递数组给php
来源:互联网 发布:java rpc框架对比 编辑:程序博客网 时间:2024/05/21 08:53
在一个项目里需要用jquery post一个可变的数组
上代码
//取出人物数量
var int_person = $('[id^=person]').size();
var item = [];
for(var i =0;i
var people_id = $('[id^=person]').eq(i).attr('id');
var people_x =parseInt($('[id^=person]').eq(i).css('left').substring(0,$('[id^=person]').eq(i).css('left').lastIndexOf("px")));
var people_y =parseInt($('[id^=person]').eq(i).css('top').substring(0,$('[id^=person]').eq(i).css('top').lastIndexOf("px")));
var people_z =parseInt($('[id^=person]').eq(i).css('z-index'));
item.push(people_id+'|'+people_x+'|'+people_y+'|'+people_z);
}
//取出物品数量
var int_item = $('[id^=item]').size();
for(var i =0;i
var item_id = $('[id^=item]').eq(i).attr('id');
var item_x =parseInt($('[id^=item]').eq(i).css('left').substring(0,$('[id^=item]').eq(i).css('left').lastIndexOf("px")));
var item_y =parseInt($('[id^=item]').eq(i).css('top').substring(0,$('[id^=item]').eq(i).css('top').lastIndexOf("px")));
var item_z = parseInt($('[id^=item]').eq(i).css('z-index'));
item.push(item_id+'|'+item_x+'|'+item_y+'|'+item_z);
}
var url = 'XXXXXXXXXX.php';
var data = {'item[]':item};
$.post(url,data,function(return_data){
alert(0);
}
)
当var data ={'item[]':item};
用item[]时
post参数
item[]person2|0|0|110
item[]person3|0|0|112
item[]person4|0|0|114
item[]person5|0|0|116
item[]person6|0|0|118
item[]person12|0|0|120
item[]item7|0|0|100
item[]item8|0|0|102
item[]item9|0|0|104
item[]item10|0|0|106
item[]item11|0|0|108
接受时代码
var_dump($_REQUEST);
显示为:
array(1) {
["item"]=>
array(11) {
[0]=>
string(15) "person2|0|0|110"
[1]=>
string(15) "person3|0|0|112"
[2]=>
string(15) "person4|0|0|114"
[3]=>
string(15) "person5|0|0|116"
[4]=>
string(15) "person6|0|0|118"
[5]=>
string(16) "person12|0|0|120"
[6]=>
string(13) "item7|0|0|100"
[7]=>
string(13) "item8|0|0|102"
[8]=>
string(13) "item9|0|0|104"
[9]=>
string(14) "item10|0|0|106"
[10]=>
string(14) "item11|0|0|108"
}
}
而是用var data ={'item':item};注意没有中括号时
itemperson2|0|0|110
itemperson3|0|0|112
itemperson4|0|0|114
itemperson5|0|0|116
itemperson6|0|0|118
itemperson12|0|0|120
itemitem7|0|0|100
itemitem8|0|0|102
itemitem9|0|0|104
itemitem10|0|0|106
itemitem11|0|0|108
接受代码一样
var_dump($_REQUEST);
注意显示
array(1) {
["item"]=>
string(14) "item11|0|0|108"
}
只有一个值
所以post array值时data中key必须加[]
- 用jquery用post传递数组给php
- error:jquery 用$.post 传递给php页面值时,没有返回
- js用post传送数组给php格式转换
- Delphi通过POST传递参数给PHP
- php用post传递字符串重定向
- 用PHP表单传递数组
- php用Ajax传递数组
- jquery使用ajax传递数组给struts2
- js传递二维数组给php
- java程序用post方式给某一网页传递参数
- jquery如何向php POST 数组
- jQuery的教程:PHP数组传递JSON
- jQuery的教程:PHP数组传递JSON
- Jquery post 传递数组方法 asp.net mvc
- jquery ajax post 传递数组 ,多checkbox 取值
- php jquery ajax 无法传递POST值的问题
- php中通过post和get传递数组的方法
- jQuery post数据给php的代码例子
- PHP基础empty和isset
- jquery判断ID是否存在的方法
- 用jquery解析JSON数据的方法
- JS获取表格行数列数单元格
- JQuery使用Ajax同步提交数据
- 用jquery用post传递数组给php
- eval和json.parse的使用
- Firefox 不支持 DOM 对象的 outerHTML innerText outerText 属性
- 在js中for in的用法
- js中innerHTML用法
- js窗口间通信摘要
- js打开新窗口并传递内容的问题
- 用socket实现的PHP的http类
- PHP和Socket