在發送通過JavaScript AJAX請求,而不依賴於jQuery的方面,這是一個非常寬泛的問題。你應該可能review the documentation here。
一個簡單的例子
// Old compatibility code, no longer needed.
if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+ ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 6 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.open('POST', url);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var data = /* some data here */
httpRequest.send('data=' + encodeURIComponent(data));
要獲得這個在PHP中你可以使用任何$_POST
或file_get_contents('php://input')
取決於請求發送Content-type
頭。上面的例子中,我們使用了一個application/x-www-form-urlencoded
Content-type
標頭,其中有一個POST
HTTP動詞,因此信息將填充在$_POST['data']
中。
一個谷歌搜索 「JavaScript的AJAX例如」 顯示很多很多的例子。包括在這裏堆棧溢出:http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery至於如何獲取PHP中的數據,任何介紹性的PHP教程將顯示如何讀取GET和POST數據。 – David
@David你不明白我的問題,我不想發送post/data中的數據我想發送它在請求正文 –
這是一個POST請求*做*。它在請求主體中發送數據。如果問題的內容比問題的內容更多,也許你可以在問題本身中進行闡述?包括您嘗試的內容和您卡住的位置的示例。 – David