簡體   English   中英

無法使用jQuery Ajax POST方法發布到PHP

[英]Cannot post to PHP using jQuery Ajax POST method

我試圖使用jQuery Ajax POST方法將數據發送到PHP文件,但PHP文件似乎沒有從Ajax獲取數據。

if (y == 5) {
  window.location = "../flashcard/indexFlashcard.php";
  $.post("indexSatzeargenzung.php", data:{p: punkt});
}

這是我試圖發布數據和通常應該獲取數據的PHP代碼的方式:

$punkt = $_POST["p"]; echo $punkt;

它顯示此通知:

注意:未定義的索引:第2行的xxx \\ xxx \\ indexSatzeargenzung.php中的p

我真的被困在這里了。

使用jQuery庫。 jQuery post()方法

$.post( "indexSatzeargenzung.php", {p: punkt})
    .done(function( data ) {
        window.location = "../flashcard/indexFlashcard.php";
    });

您可以使用.ajax而不是.post方法:

if (y == 5) {
    $.ajax({
        type: "POST",
        url:"indexSatzeargenzung.php", 
        data: "p=" + punkt,
        complete: function() {
            window.location = "../flashcard/indexFlashcard.php";
        }
    });
}

暫無
暫無

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

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