Ajax 调用在本地服务器上产生 403 错误

问题描述 投票:0回答:0

我在 Windows 11 下使用本地域 tvcdev.local 运行 Wamp64。任何在 Javascript 下尝试对除包含调用脚本的目录以外的任何同级目录中的脚本进行 Ajax 调用的尝试都会失败,并显示 403 错误。

调用示例:

function logError(errMsg)
{
  $.ajax({
    type: 'POST',
    data:{'logerror': errMsg},
    url:'/php/inc/errorhandler-inc.php',
  });
}

虽然这是对错误处理程序的调用,但它并不是一个特定的错误问题,因为 403 错误发生在对目录中的任何脚本的任何 Ajax 调用中,例如“/php/main”或“/php/ajax”同级别。

Apache 日志说:

\[Wed Mar 08 10:14:47.003011 2023\] 
\[access_compat:error\] \[pid 15976:tid 1264\] 
\[client ::1:56426\]  AH01797: client denied 
by server configuration: D:/localserver/volcentre
/tvcdev/php/inc/errorhandler-inc.php, referer:  
http://tvcdev.local/volreg.html

这些是典型的通话标头:

Request URL: http://tvcdev.local/php/inc/errorhandler-inc.php    
Request Method: POST    
Status Code: 403 Forbidden    
Remote Address: [::1]:80    
Referrer Policy: strict-origin-when-cross-origin    
Connection: Keep-Alive    
Content-Length: 308    
Content-Type: text/html; charset=iso-8859-1    
Date: Wed, 08 Mar 2023 11:11:40 GMT    
Keep-Alive: timeout=5, max=96    
Server: Apache/2.4.51 (Win64) PHP/8.1.15 mod_fcgid/2.3.10-dev    
Accept: */*    
Accept-Encoding: gzip, deflate    
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8    
Connection: keep-alive    
Content-Length: 920    
Content-Type: application/x-www-form-urlencoded; charset=UTF-8    
Cookie: XDEBUG_SESSION=netbeans-xdebug; TVCFORMS=qnscpme0jc6irog82lqj0570ls    
Host: tvcdev.local    
Origin: http://tvcdev.local    
Referer: http://tvcdev.local/volreg.html    
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36    
X-Requested-With: XMLHttpRequest

我看不出如何修改服务器配置来解决它。

我已经测试了各种目录。接受对父目录中脚本的调用。

问题纯粹是本地问题,生产托管 Web 服务器不受影响。

编辑:先前将

httpd-vhosts.conf
中的相关条目从“需要本地”更改为“需要所有授予”的建议并没有解决我的问题。

javascript ajax http-status-code-403
© www.soinside.com 2019 - 2024. All rights reserved.