这是我的 html javascript
$.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.");
?>
成功发布,但是当我执行结果的 console.log 时,它在 firebug 中显示(一个空字符串)。有人可以帮我解决这个问题吗?谢谢
我想以 JSON 类型返回。