Home > Backend Development > PHP Tutorial > ajax?表单出错

ajax?表单出错

WBOY
Release: 2016-06-20 12:49:42
Original
966 people have browsed it

 <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;?>
Copy after login



回复讨论(解决方案)

var result = jQuery.parseJSON(result); alert(result.password);
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template