AJAX POST请求不适用于代码段

时间:2019-01-24 22:10:23

标签: javascript php html ajax

我正在使用调用发布功能的“发送”按钮将JSON字符串发送到服务器。但是由于某种原因,响应始终为FALSE。我得到的状态码是200。所以我开始认为问题出在php处理程序中。如果有人看到我不是我,我将不胜感激。

谢谢!

PHP

$con = mysqli_connect("localhost", "user", "password", "database"); 
/*here I set up the connection with my respective user & password*/

$entry = $_POST["entry"];
$entry= json_decode($entry);

$statement = mysqli_prepare($con, "INSERT INTO table (entry) VALUES (?) ");
mysqli_stmt_bind_param($statement, "s", $entry);
mysqli_stmt_execute($statement);

$response = array();

$response["success"] = false;  

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;  
}

JS

function posting(){
    var posting_date = String(document.getElementById('date').innerHTML);
    url= 'URL/post.php'; //URL is basically my web server
    var entry= {entry: posting_date};


                    $.ajax({
                             type: "POST",
                             url: url,
                             data: JSON.stringify(entry),
                             dataType: "json"
                            });

                }

0 个答案:

没有答案