ajax提交,后台没法写代码

WBOY
Release: 2016-06-23 13:50:25
Original
721 people have browsed it

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

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

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

直接输出$a可以,但是执行操作数据库的代码就不能输出了。操作数据库代码正确,没有问题


回复讨论(解决方案)

看控制台,有什么提示?

看控制台,有什么提示?


没有任何提示

在ajax.php中把id赋一个固定的值,单独打开ajax.php看一下,就应该明白了

在ajax.php中把id赋一个固定的值,单独打开ajax.php看一下,就应该明白了


可以,正常输出。你的意思是ajax没有提交过去?不应该呀,前台不动,后台改成这样就可以正常输出
$a = $_POST["id"]; print_r( $a);
Copy after login

在ajax.php中把id赋一个固定的值,单独打开ajax.php看一下,就应该明白了


已经找到问题了,不能直接输出,而是要输出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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!