用jquery异步向B页面传递一系列参数:
$.get('get.php?a="+ Math.random()', {name: $(this).val()}, function(data) {
alert(unescape(data));
});
其中$(this).val()为一组数据,其值为1,2,3,4 通过jquery 的$.get方法向B页面传这组数据,如何在B页面用数组接收这组数据并用数组的索引显示出来,比如echo $name[1]就可以打印出2。
$.get('get.php?a="+ Math.random()', {name: $(this).val()}, function(data) {
alert(unescape(data));
});
其中$(this).val()为一组数据,其值为1,2,3,4 通过jquery 的$.get方法向B页面传这组数据,如何在B页面用数组接收这组数据并用数组的索引显示出来,比如echo $name[1]就可以打印出2。
$("#sel").each(function(){
$(this).children("option").each(function(){
/* alert($(this).val())*///每一个option
$.get('get.php?a="+ Math.random()', {name: $(this).val()}, function(data) {
alert(unescape(data));
}); });
});
});
})传递的内容就是遍历ID为sel的select对象,获取SELECT对象的每个option的值然后挨个传递到B页面,B页面用$_GET["name"]获取该组数据,我想做的是用数组去保存$_GET["name"]的数据,然后可以通过数组的索引比如$names[1]可以打印出该索引的值。
print_r($arr);//输出结果
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
而是这样的
$_GET['name'] = '1’;
$_GET['name'] = '2’;
$_GET['name'] = '3’;
$_GET['name'] = '4’;
Array
(
[0] => 1
)
Array
(
[0] => 2
)
Array
(
[0] => 3
)
Array
(
[0] => 4
)
我这样去拼装他也不行:$names.=$name.','打印出来的依然是1234,就是第一个对话框弹出1,确定后弹出第二个对话框2……B页面的代码<?php
$name=$_GET["name"]=iconv("UTF-8","gb2312",$_GET["name"]);
/*for ($i = 1; $i <=$name; $i++)
{
$names.=$name.',';*/
/*$names=array($name+',');*/
/*}
*/
$arr = explode(',', $_GET['name']);
print_r($arr[0]); /*print_r ($names);*/
?>
你可以在项目里运行一下试试
你看是不是数组吧,是的话直接读数组就是了.
如果不是那你的1楼传递方法就不正确.我只知道表单可以这样,不清楚你这种样子行不行.
另外你直接传递json数据过来不就可以了吗?想那么多...绕那么多路
请贴出 print_r($_GET); 的结果
var_dump($_GET['name']);
出来的结果还依然是弹出第一个对话框内容是:string(1)"1"确定后弹出第二个对话框内容是:string(2)"2"再确定后弹出第三个对话框内容是:string(3)"3"最后弹出第四个对话框内容是:string(4)"4"
我想达到的效果是把这些数字统一放到一个数组里面,然后我想取那个就是哪个,比如我想取arr[1]就弹出2,现在的问题是,有多少个数据会弹出多少个对话框。请问转JSON数据吃过来如何做?
$.get('get.php?a="+ Math.random()', {name: $(this).val()}, function(data) {
alert(unescape(data));
});
吗?
怎么可能弹出多次对话框!
,Array
(
[0] => 2
)
php里我想把这样Array
(
[0] => 2
)
的格式我只想取出2来怎么取啊?
$.post("url.php",{"data[]":new Array('1','2')},function(data){alert(data);});
php:
$list = $_POST['data'];
print_r($list);却成这样的格式
,Array
(
[0] => 2
)
php里我想把这样Array
(
[0] => 2
)
的格式我只想取出2来怎么取啊?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/javascript" src="js/jquery-1.4.1.js"></script>
<script>
$(function(){
$("select").each(function(){
$(this).children("option").each(function(){
$.get('get.php', {name: $(this).text()}, function(data) {
alert(data);
});
});
});
});
</script>
</head><body>
<select id="test1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select></body>
</html>
PHP部分代码
<?php
$name=$_GET["name"];
print_r($name);?>
这是完整的代码,我想要的结果是$name的值全部放一个容器里,数组或者session或者view里,然后我可以通过索引我想取这个容器里的值就取出来。通过代码运行可以知道$name的值是1,2,3,4 我就是想通过索引取出1234中的某个值。不知道怎么做?