D
D
Dymok2019-05-13 18:48:08
JavaScript
Dymok, 2019-05-13 18:48:08

AJAX request not working properly due to .htaccess?

Actually, you need to fasten the form submission with the help of AJAX, but it does not work because of the existing .htaccess - the POST array does not reach PHP (if you remove .htaccess, then everything is OK).

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L,QSA]
RewriteCond %{THE_REQUEST} ([^\s]*)\.php(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]


ajax request:
$.ajax({
                    url: 'handler.php',
                    type: 'POST',
                    data: data,
});


How and is it possible to fix the AJAX request without touching .htaccess?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-05-13
@UnluckySerivelha

Correct the request address by removing the .php.
Or add an exception for POST requests to .htaccess.

.htaccess
RewriteEngine On

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ([^\s]*)\.php(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L,QSA]

I
iBird Rose, 2017-04-30
@Melman229

inline - this css is written in the html document itself in the <style> tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question