在使用Jquery和PHP发布Ajax之后返回(空字符串)
这是我的html javascript在使用Jquery和PHP发布Ajax之后返回(空字符串),php,javascript,jquery,mysql,Php,Javascript,Jquery,Mysql,这是我的html javascript $.ajax({ url: 'post.php', type: "POST", data: 'name="dan"', success: function(result){ console.log(result); }, error: function(){ console.log('error');
$.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.");
?>
您需要通过echo
返回一些内容
另外,我强烈建议你阅读 您需要通过echo
返回一些内容
另外,我强烈建议你阅读 您的代码应该如下所示:
$.ajax({
url: 'post.php',
type: "POST",
data: {name: "dan"},
success: function(result){
console.log(result);
},
error: function(){
console.log('error');
}
});
result
=在您的post.php中回显的内容
如果没有回显或打印任何内容,它将不会返回任何内容。您的代码应该如下所示:
$.ajax({
url: 'post.php',
type: "POST",
data: {name: "dan"},
success: function(result){
console.log(result);
},
error: function(){
console.log('error');
}
});
result
=在你的post.php中回显的内容
如果没有回显或打印,它将不会返回任何内容。你不会返回任何内容。来吧-解决方法:添加一些条件if/else
然后根据我刚刚学习的php、ajax、,还有一个小时前的jquery。你没有返回任何东西。来吧-解决方法:添加一些条件if/else
,然后根据一个小时前我刚学过的php、ajax和jquery的语法做echo
。是的,ajax中发送的数据仍然让我感到困惑,因为它是通过JSON语法发送的。使用name=“dane”
“dane”代替'name=“dane”
是的,在AJAX中发送的数据仍然让我感到困惑,因为它是在JSON语法上发送的。不要使用'name=“dane”
'而使用名称:“dane”