[英]AJAX - XMLHttpRequest open php file outside htdocs
這是簡化的代碼,我在epr_lib.php中調用JS。
epr_lib.php位於cgi-bin文件夾中,表示在htdocs外部。
在cgi-bin文件夾中,我有以下文件:epr_lib.php; newrequest.php。
我的問題是:如何調用ajaxRequest.open htdocs之外的文件? 還是這不可能?
var ajaxRequest;
ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
suppl_addrss.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "newrequest.php?task=getsuppladdrss", true);
ajaxRequest.send(null);
謝謝。
不,不可能。 Ajax請求對文件發出http請求,因此您必須在htdocs中使用它。
您可以創建一個代理腳本來加載cgi-bin文件。 只需創建一個包含您的cgi-bin文件的文件:
// myproxy.php
// you'll have to get the querystring and use it as a variable in newrequest.php
$vars = $_GET("task");
include('../cgi-bin/newrequest.php');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.