簡體   English   中英

將帶有Ajax的JavaScript數組發送到PHP返回Null

[英]Sending JavaScript Array with Ajax to PHP returns Null

我嘗試將JS數組發送到php,但是發布數據始終返回null。 這是我的JavaScript代碼:

console.log($Seats);
console.log($Seats.toString());
console.log(JSON.stringify({ $Seats }));
var jsonStr = JSON.stringify($Seats);
 $.ajax({
    url     : 'database-files/addseatmaps.php',
    type    : 'POST',
    data    : {seater: jsonStr } ,
    success : function (data) {

    console.log(data);


    },error: function( error )
{
                                        //$("#loadingmessage").modal('hide');
$.Notification.autoHideNotify('error', 'top right', 'Submission Error','Check Internet Connection');
    submit.ladda( 'stop' );
                    },
    cache: false,
    processData: false,  
    contentType: false
    });
     return false;

這是我的PHP代碼:

<?php
require_once("../classes/mysql.class.php");
session_start();

$insert = new MYSQL();
$busexist = new MySQL;

//echo date_default_timezone_get();

$d=strtotime("now");
$date =  date("d/n/Y H:i:s", $d);
$time =  date("H:i:s", $d);


$myArray = json_decode($_POST['seater']);

var_dump($myArray);
?>

這是我得到的輸出:

<pre class='xdebug-var-dump' dir='ltr'>
<small>D:\wamp64\www\lorrybus_admin\database-files\addseatmaps.php:22:
</small><font color='#3465a4'>null</font>
</pre>

我不知道我在做什么錯,但是我已經盡一切可能仍然沒有結果。

去掉

processData: false,  
contentType: false

您需要使用jquery處理數據以將其轉換為正確的類型(application / x-www-form-urlencoded),並且需要設置內容類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM