这是我的html的javascript返回(空字符串),POST阿贾克斯后使用jQuery和PHP
$.ajax({
url: 'post.php',
type: "POST",
data: 'name="dan"',
success: function(result){
console.log(result);
},
error: function(){
console.log('error');
}
});
这里是post.php中
<?php
$host = "localhost";
$dbname = "test";
$user = "";
$pass = "";
$conn = mysql_connect($host, $user, $pass) or die (MYSQL_ERROR);
$select_db = mysql_select_db($dbname) or die("Could not select the database.");
$name = $_POST["name"];
$sql = "INSERT INTO user VALUES (null, '$name')";
mysql_query($sql) or die("Could not execute query.");
?>
成功发布,但是当我做控制台。日志的结果,它显示(一个空字符串)在萤火虫。任何人都可以帮我解决这个问题吗?谢谢
我想返回作为JSON类型。
你没有任何回报。 – 2012-08-03 01:48:50
来吧 - 工作:添加一些条件'if/else'然后做'echo'取决于 – Yang 2012-08-03 01:51:50
对不起我刚刚在1小时前学过php,ajax和jquery。 – Vicheanak 2012-08-03 02:07:21