dojo使用post方式发送数组请求
最近做了dojo1.9的程序,发现用post方式可以向数据库端发送数组参数,后台用的是php+mysql数据库。 前台代码: /用post方式发送大量数据 request.post("./data.php",{ query:{ funcname:"queryGasStationArray"//在php端可以用$funcname=$_GET["funcname"];//获得funcname的值,即“queryGasStationArray” }, data:arrayList.toArray(), handleAs:"xml", timeout:1000 } ).then(function(data){//处理返回的数据 Varc=data.getElementsByTagName("gastation");//标签名,看下面的xml数据格式输出 },function(error){ console.log(error); }); 其中arrayList是一个ArrayList对象,不明白的可以查帮助。用toArray函数将它转化为数组,就可以发送了。 后台代码: <?php header('Content-Type:text/xml'); header("Cache-Control:no-cache,must-revalidate"); //Adateinthepast header("Expires:Mon,26Jul199705:00:00GMT"); header("Access-Control-Allow-Origin:*"); $funcname=$_GET["funcname"]; $con=mysql_connect('localhost','zhengluchuan','1234567'); if(!$con) { die('Couldnotconnect:'.mysql_error()); } mysql_select_db("automobileServiceSystem",$con); switch($funcname){ case"queryGasStationArray": echo'<?xmlversion="1.0"encoding="utf-8"?> <gasStations>'; $stationArray=$_POST;//获得所有用post方式获得的数据,即dojo中data参数中的内容。其实是个数组 $count=count($stationArray);//获得数组的长度 if($count>0){ for($i=0;$i<$count;$i++){//遍历数组输出 $sql="SELECT*FROM加油站WHEREname='".$stationArray[$i]."'";//查询数据库 $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { echo"<gastation>"; echo"<oil>".$row['oil']."</oil>"; echo"<details>".$row['details']."</details>"; echo"<MapX>".$row['MapX']."</MapX>"; echo"<MapY>".$row['MapY']."</MapY>"; echo"</gastation>"; } } } echo"</gasStations>"; break; default: echo"没有此查询条件,请确认后重试!"; break; } ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |