[英]Ajax data not sending, but requesting file
我正在嘗試使用帶有xhttprequest的ajax構建聊天系統。 我請求文件,文件響應,但是獲取數據未到達該文件。 我嘗試即使在發布后也將其發送,但仍然無法將數據發送到php文件。 這是請求文件的函數:
function refreshChat(){
if(username != ""){
var date = new Date();
var timezone_offset = date.getTimezoneOffset();
$(".messages-container").empty();
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
$(".messages-container").html(this.responseText);
}
};
xhttp.open("GET", "/chat/ajax_requests/get_messages.php", true);
xhttp.send("receiver="+username+"&sender="+chat_with+"&limit="+limit+"&timezone_offset_minutes="+timezone_offset);
}
}
所請求的文件具有以下內容:
$receiver = $_GET['receiver'];
$sender = $_GET['sender'];
$limit = $_GET['limit'];
$timezone_offset_minutes = $_GET['timezone_offset_minutes'];
怎么了?
所以我在w3schools上發現了這個:send(string):將請求發送到服務器。 用於POST請求send():將請求發送到服務器。 用於GET請求
我建議您將來自send函數的字符串添加到url中,如下所示:
xhttp.open("GET", "/chat/ajax_requests/get_messages.php?"+"receiver="+username+"&sender="+chat_with+"&limit="+limit+"&timezone_offset_minutes="+timezone_offset, true);
xhttp.send();
那么您將使用send函數來獲取請求。
鏈接到文檔: https : //www.w3schools.com/xml/ajax_xmlhttprequest_create.asp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.