我必須使用XMLHttpRequest,但我不知道函數request.send()
預期哪種數據格式。我現在搜索了太久。XMLHttpRequest - request.send(data)期望哪種格式的數據?
我試圖通過一個JSON對象,但它不工作:
var request = new XMLHttpRequest();
request.open("GET","fileApi");
var data = {
action: "read",
targetFile: "testFile"
};
request.addEventListener('load', function() {
if (request.status >= 200 && request.status < 300) {
$("#messageOutput").html(request.responseText);
} else {
console.warn(request.statusText, request.responseText);
}
});
request.send(data);
我得到updateFile:155 XHR finished loading: GET "http://localhost/cut/public/fileApi".
但沒有數據在服務器上接收。我做了這個簡單的檢查,批准這樣的:
PHP(服務器端):
$action = filter_input(INPUT_GET, "action");
$targetFile = filter_input(INPUT_GET, "targetFile");
echo ("action = '$action' | targetFile = '$targetFile'");
exit();
返回:行動= '' |的TargetFile =「」
可惜的是,我不能在我的應用程序使用jQuery,因爲目標是一個C#瀏覽器上(Internet Explorer)中,它檢測到jQuery的文件中的錯誤,並從工作停止我的劇本......
['send'](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send)接受一個字符串或一個FormData對象,或者自最近的一個二進制數據版本。 – Bergi
「*一個C#Webbrowser(Internet Explorer)*」 - wat? jQuery應該在IE中工作,如果有必要的話,可以嘗試使用舊版本。 – Bergi
這看起來像服務器端的PHP,您可以控制的代碼。您希望在那裏使用哪種數據格式? – Bergi