Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用Jquery和PHP发布Ajax之后返回(空字符串)_Php_Javascript_Jquery_Mysql - Fatal编程技术网

在使用Jquery和PHP发布Ajax之后返回(空字符串)

在使用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');

这是我的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.");


?>

您需要通过
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”