Home  >  Article  >  Backend Development  >  PHP+AJAX+JQUERY+JSON回到JSON值是UNDEFINE

PHP+AJAX+JQUERY+JSON回到JSON值是UNDEFINE

WBOY
WBOYOriginal
2016-06-13 10:33:23862browse

PHP+AJAX+JQUERY+JSON返回JSON值是UNDEFINE
index.php ajax部分

 

后台ajax.php


header("cache-control:no-cache,must-revalidate"); 

  header('Content-Type: text/html; charset=gb2312'); 

  $name=$_GET["name"];

  $email=$_GET["email"];

  $date=date( "Y-m-d H:i:s ");

  $message=$_GET["message"];

  $link=mysql_connect("localhost","root",""); 

  mysql_query("set names 'gbk'"); 

  mysql_select_db("liuyan");

  $exec="insert into liuyan (name,email,message,date) values ('$name','$email','$message','$date')"; 

  $a=array('name'=>$name,'email'=>$email,'message'=>$message,'date'=>$date);

  echo json_encode($a);

  mysql_close(); 

?>
get传值没问题后台数据一直没添加到数据库里面求大神们帮下忙

------解决方案--------------------
var json=eval("("+json+")");

 这不对啊,直接:

var json = eval(json);就行了啊,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