Maison > Article > développement back-end > 利用Pear:HTML_AJAX提交表单时数组只提交了第一个值解决思路
利用Pear::HTML_AJAX提交表单时数组只提交了第一个值
User.php
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php class User{ function additem(){ // session_start(); // $u = $_SESSION["User"]; $item = array('name'=>$_POST["name"], 'sex'=>$_POST["sex"], 'age'=>$_POST["age"]); // $u[] = $item; // $_SESSION["User"] = $u; // return $u; return $item; } }?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php session_start(); include 'HTML/AJAX/Server.php'; include 'User.php'; $server = new HTML_AJAX_Server(); $u = new User(); $server->registerClass($u); $server->handleRequest();?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>index</title><script type="text/javascript" src="server.php?client=all&stub=all"></script><script type="text/javascript">function test(r){ var target = HTML_AJAX_Util.getElement("target"); var s = ''; /* for (var i=0; i<r.length; i++) { var rowdata = r[i]; s += '<h4>sex:'+rowdata["sex"]+'<br>'; s += '<h4>name:'+rowdata["name"]+'<br>'; s += '<h4>age:'+rowdata["age"]+'<br>'; }*/ var rowdata = r; s += '<h4>name:'+rowdata["name"]+'<br>'; s += '<h4>sex:'+rowdata["sex"]+'<br>'; s += '<h4>age:'+rowdata["age"]+'<br>'; target.innerHTML = s;}</script><pre id="target">