Home  >  Article  >  Backend Development  >  利用Pear:HTML_AJAX提交表单时数组只提交了第一个值解决思路

利用Pear:HTML_AJAX提交表单时数组只提交了第一个值解决思路

WBOY
WBOYOriginal
2016-06-13 13:43:13883browse

利用Pear::HTML_AJAX提交表单时数组只提交了第一个值
User.php

PHP code
<!--

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;
        }
    }
?>



Server.php

PHP code
<!--

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();
?>



index.php

PHP code
<!--

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">



提交后只能显示name,而sex和age都是null,为什么?

------解决方案--------------------


name=sex" : HTML把这个当属性了吧?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn