Ajax调用找不到PHP文件 [英] Ajax call cannot find PHP file
问题描述
我正在执行ajax调用,但给出错误消息,提示未找到404文件.
I am doing a ajax call , but its giving a error saying 404 file not found.
$.ajax({
type : 'POST',
url : 'app/lib/functions.php',
data : data,
success : function(data) {
}
});
我的项目结构是这个
我正在从main.js(在公共文件夹中)到functions.php(在app文件夹中)进行ajax调用. 请帮忙.我对此感到厌倦. 我尝试在ajax中的URL前面使用../和../../,但是它不起作用.我认为这与app文件夹有关,因为该文件夹不适用于客户端,类似这样.我现在不知道如何做阿贾克斯. 我的.htaccess具有此代码,因为默认情况下我将重定向到公用文件夹.
I am doing a ajax call from main.js (in public fodler) to functions.php (in app folder). Please help. I am tired of this. Edited : I tried with ../ and ../../ in front of the url in ajax but it does not work. I think its something to do with app folder , as this folder is not available to client side , something like that. I dont know how to do the ajax now. My .htaccess has this code as I am redirecting to public folder by default.
RewriteEngine On
RewriteBase /proj_name/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
编辑:如果删除.htaccess,则'../app/lib/functions.php'路径有效
EDIT : If I remove the .htaccess , '../app/lib/functions.php' path works
推荐答案
我不太使用AJAX,但我认为它应该指向路由,而不是直接指向文件.那条道路是相对的,永远不会真正解决.
I don't use AJAX much but I believe it should be pointing to a route, not directly to a file. That path would be relative and never actually resolve.
这篇关于Ajax调用找不到PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!