利用Pear::HTML_AJAX提交表单时数组只提交了第一个值
User.php
<?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; } }?>
<?php session_start(); include 'HTML/AJAX/Server.php'; include 'User.php'; $server = new HTML_AJAX_Server(); $u = new User(); $server->registerClass($u); $server->handleRequest();?>
<!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>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"]+'</h4><br>'; s += '<h4>name:'+rowdata["name"]+'</h4><br>'; s += '<h4>age:'+rowdata["age"]+'</h4><br>'; }*/ var rowdata = r; s += '<h4>name:'+rowdata["name"]+'</h4><br>'; s += '<h4>sex:'+rowdata["sex"]+'</h4><br>'; s += '<h4>age:'+rowdata["age"]+'</h4><br>'; target.innerHTML = s;}</script></head><body><pre id="target"></pre><form id="form1" name="form1" method="post" action="server.php" onsubmit="return!HTML_AJAX.formSubmit(this,function(result){test(result);},{className:'User',methodName:'additem'} );"><p> <label>NAME <input type="text" name="name" id="name"/> </label></p><p> <label>SEX <input type="text" name=sex" id="sex"/> </label></p><p> <label>AGE <input type="text" name=age" id="age"/> </label></p><p> <label> <input type="submit" name="button" id="button" value="submit" /> </label></p></form></body></html>