dqudtskm49788
2016-05-05 05:54
浏览 57
已采纳

使用ajax时php中未定义的索引

My Form page :

<body>  
<head>
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script>
        function val()
        {
            var name=document.getElementById("name").value;
            if(name == '')
            {
                alert(name+" is empty");
            }
            else
            {
            var dataString = "name = "+name;
            $.ajax({
                type:"POST",
                url:"hi.php",
                data:dataString,
                cache:false,
                success:function(html){
                    $('#msg').html(html);
                }
            });
            }
        return false;
        }
        </script>

    </head>
<body>
    <form>
        <input type="text" id="name" >
        <br/><br/>
        <input type="submit" value ="submit" onclick="return val()">
    </form>
<p id="msg"></p>
</body>

Here is my hi.php file

<?php
$name = $_POST["name"];
echo "Response : ".$name;
?>

When clicking on submit button it show an error Notice: Undefined index: name in C:\wamp\www\SendEmailAjaxJquery\hi.php on line 2

I don't know where is the error plz help me to find out the error...

Thanks in advance

3条回答 默认 最新

相关推荐 更多相似问题