Ajax调用无法找到url,因为.php已在URL中删除

时间:2018-04-12 12:49:06

标签: javascript php ajax .htaccess

正如标题所说,我的 AJAX POST电话似乎无法找到其网址。这是因为在 .htaccess 文件中,我从网站的网址中删除了 .php

明显的错误

http://localhost/style-faq/includes/handlers/ajax/giveView 404 (Not Found)

的.htaccess

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://localhost/myWebsite/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://localhost/myWebsite/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

AJAX POST电话

function giveView(id){
    $.post("includes/handlers/ajax/giveView.php", //already tried without .php
                {
                    id: id
                })

                .done(function(response){
                    console.log(response);
                })
}

有没有办法让 AJAX 调用正确的网址?或者是解决 .htaccess 代码的唯一解决方案,并在网址中看到 .php 过着充实的生活。

0 个答案:

没有答案