[英]Cannot post to PHP using jQuery Ajax POST method
I am trying to send data to a PHP file using jQuery Ajax POST method but the PHP file doesn't seem to get the data from Ajax. 我试图使用jQuery Ajax POST方法将数据发送到PHP文件,但PHP文件似乎没有从Ajax获取数据。
if (y == 5) {
window.location = "../flashcard/indexFlashcard.php";
$.post("indexSatzeargenzung.php", data:{p: punkt});
}
This is the way I'm trying to post the data and the PHP code that normally should get the data is: 这是我试图发布数据和通常应该获取数据的PHP代码的方式:
$punkt = $_POST["p"]; echo $punkt;
It displays this notice: 它显示此通知:
Notice: Undefined index: p in xxx\\xxx\\indexSatzeargenzung.php on line 2
注意:未定义的索引:第2行的xxx \\ xxx \\ indexSatzeargenzung.php中的p
I'm really stuck here. 我真的被困在这里了。
Use the jQuery Library. 使用jQuery库。 jQuery post() Method
jQuery post()方法
$.post( "indexSatzeargenzung.php", {p: punkt})
.done(function( data ) {
window.location = "../flashcard/indexFlashcard.php";
});
You can use .ajax instead of .post method: 您可以使用.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.