ajax提交,后台老板没法写代码

WBOY
Release: 2016-06-13 12:06:06
Original
892 people have browsed it

ajax提交,后台没法写代码
ajax可以提交到后台,后台也能获取到提交的数据,直接输出可以,但是写一些其他处理代码,就没法输出json了

<br />$(document).ready(function(){  <br />        //post()方式  <br />        $('#test_post').click(function (){   <br />            $.post(  <br />                'ajax.php',  <br />                {  <br />                     		id:$("#id").val(),                   <br />                },  <br />                function (data) { //回调函数  <br />                    var myjson='';  <br />                    eval('myjson=' + data + ';');  <br />					alert(data);<br />                    $('#result').html("ID为:" + myjson.username);  <br />                }  <br />            );  <br />        });  <br />       <br />});  <br />
Copy after login

<br />  $a = $_POST["id"];	   <br />		 $conn  = mysql_connect("localhost","root",""); <br />		 $my_db = mysql_select_db("demo",$conn);<br />		 $sql="select * from demo where id = $a";<br />	    $result = mysql_query($sql, $conn);<br />		$userInfo = mysql_fetch_assoc($result);             <br />	<br />	    print_r($userInfo);<br />	//   echo $a;<br />
Copy after login

直接输出$a可以,但是执行操作数据库的代码就不能输出了。操作数据库代码正确,没有问题
------解决方案--------------------
看控制台,有什么提示?
------解决方案--------------------
在ajax.php中把id赋一个固定的值,单独打开ajax.php看一下,就应该明白了

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