我想編程一個在線實驗,它將一些數據使用jQuery和ajax發佈到一個將腳本數據保存到文本文件的PHP腳本中,而且我遇到了一些問題。當我發佈的數據很小(比如2kb)並且能夠正確保存發佈的數據時,腳本工作正常,但是當帖子中的數據變爲4kb或更大時,我得到一個404錯誤,而PHP腳本不會運行在全部(沒有數據保存到文件),這是非常奇怪的。下面是相關的JavaScript和PHP代碼:jQuery Ajax發佈到PHP腳本給404錯誤
experiment.js:
$.ajax({
url: 'snippets/saveData.php',
data: {"time": time, "experimentStimuli": experimentStimuli, "experimentPredictions": experimentPredictions, "experimentPredictionsEnd": experimentPredictionsEnd},
type: 'POST'
});
saveData.php:
$_SESSION['user']['experimentStimuli'] = $_POST['experimentStimuli'];
$_SESSION['user']['experimentPredictions'] = $_POST['experimentPredictions'];
$_SESSION['user']['experimentPredictionsEnd'] = $_POST['experimentPredictionsEnd'];
foreach($_SESSION['user']['experimentStimuli'] as $key => $value) {
foreach($value as $key2 => $value2) {
fwrite($fh, $value2);
}
fwrite($fh, "\n");
}
foreach($_SESSION['user']['experimentPredictions'] as $key => $value) {
foreach($value as $key2 => $value2) {
fwrite($fh, $value2);
}
fwrite($fh, "\n");
}
foreach($_SESSION['user']['experimentPredictionsEnd'] as $key => $value) {
foreach($value as $key2 => $value2) {
fwrite($fh, $value2);
}
fwrite($fh, "\n");
}
我使用絕對URL,而不是一個相對的嘗試,但它使沒有區別(相對URL適用於小數據),我也嘗試把頭('HTTP/1.1 200 OK');在我的PHP腳本的頂部,但這似乎不工作。雖然我的網站的基礎是Wordpress,但我的實驗代碼與它是分開的,不需要任何Wordpress功能,但它顯示的404錯誤頁面是Wordpress 404頁面。我有一種感覺,WordPress可能會干擾某種方式(也因爲它在本地工作正常),但我不知道如何解決它。有任何想法嗎?在WordPress
如果你得到404.its文件未找到。 – Dgo
有你的螢火蟲嗎? – Dgo
這可能是由.htaccess將您的查詢重定向到不知道如何將URL處理爲有意義的WordPress的WordPress引起的。有人知道WordPress以及如何控制.htaccess文件,希望能幫助你,如果是這樣的話。 – h00ligan