我有一個在我的索引頁加載幾個JS腳本,包括一個JS腳本,其中包括我的AJAX功能關閉其它JS和PHP的東西
function ajaxrequest(php_file, purpose, var1, var2, var3, var4, var5, var6, var7, var8, where) {
var request = getXMLHTTP(); // call the function for the XMLHttpRequest instance
// create pairs index=value with data that must be sent to server
var the_data = 'purpose=' + purpose + '&var1=' + var1 + '&var2=' + var2 + '&var3=' + var3 + '&var4=' + var4 + '&var5=' + var5 + '&var6=' + var6 + '&var7=' + var7 + '&var8=' + var8;
request.open("POST", php_file, true); // set the request
// adds a header to tell the PHP script to recognize the data as is sent via POST
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(the_data); // calls the send() method with datas as parameter
// Check request status
// If the response is received completely, will be transferred to the HTML tag with tagID
request.onreadystatechange = function() {
if (request.readyState == 4) {
document.getElementById(where).innerHTML = request.responseText;
}
};
}
一切,包括在同一個文件中找到其他JS功能作爲上面的功能,正常工作,直到這個函數被調用。這個函數每次都有效,但是任何JS函數,PHP要求和session_start()都似乎'重置'並且需要重新加載。這是正常的,如果不是,請你協助糾正這個問題?
你說一切正常,直到這就是所謂的,這聽起來像有此函數中的代碼中有錯誤。你確定沒有錯誤嗎?如果沒有錯誤,你究竟意味着什麼停止工作?需要更多信息來弄清楚你的期望和實際發生的情況。 – Busches
Theres ajaxrequest後面的colorbox彈出窗口被觸發。 colorbox彈出窗口似乎失去了在index.php上加載的JS腳本。如果我運行colorbox彈出窗口而不運行ajaxrequest,它按預期工作。這就是爲什麼我懷疑它與ajaxrequest有關係 – AlbertaXChange