ajax?表单出错

WBOY
WBOYOriginal
2016-06-20 12:49:42969browse

 <body>       <form>            Name:<input type="text" id="txt" >            <input type="button"  value="提交" onclick="A()" >       </form>    </body>    <script>            function A() {                $.ajax({                    url: 'b.php',                    type: 'post',                    dateType: 'json',                    data: {name: $("#txt").val()},                    success: function (result) {                        alert(result.password);                      //点击提交按钮是,弹出信息 undefined  而不是  B??                    },                    error: function (result) {                        alert("error");                    }                });            }    </script>b.php:<?php   $result=array();   $result['name']=$_POST['name'];   $result['password']="B";   echo json_encode($result);   exit;?>



回复讨论(解决方案)

var result = jQuery.parseJSON(result); alert(result.password);

先alert(result)看看result是不是json对象。。。。

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