我可以使用下面的代码将任何数据发送到服务器并获得成功的结果,但我的代码不发送响应$data
是真还是假。代码是可以成功插入到数据库 localhost PHP 文件:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.post("http://www.test.com/index.php", {userCode:"ttt-ddd-fff"},
function(data){
alert (data.message);
},'json');
});
</script>
</head>
</html>
服务器:
<?php
include_once ('./AFactory.class.php');
$database= new AFactory;
$db=new AFactory();
$link=$db->getDBO();
$query=array('id'=>NULL,'userCode'=>$_POST['userCode']);
$sql=$db->insertQuery(' `test`.`users`',$query);
if ( mysql_query($sql) )
{$data['success']=true;$data['message']='ok';}
else
{$data['success']=false;$data['message']='no';}
echo json_encode($data);
?>