G
G
GM2mars2015-11-25 12:34:53
JavaScript
GM2mars, 2015-11-25 12:34:53

Why ajax request sometimes returns html page?

In an application, the backend is separated from the frontend. The entry point for the front is index.html and the backend is api.php. The front communicates with the backend through ajax requests, but some requests apparently go to index.html, resulting in an html page in the response. Requests are regulated by .htaccess, maybe I didn't configure it correctly:

AddDefaultCharset utf-8
Options -Indexes

RewriteEngine On
RewriteBase /

# if it is ajax request
RewriteCond %{HTTP:X-Requested-With} XMLHttpRequest
RewriteRule . api.php [L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html

Some requests are treated by adding a slash to the end of the address: site.ru/users/1 -> site.ru/users/1/
Now it is the problem with POST requests

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Samardak, 2015-11-25
@GM2mars

Check the headers being sent, as you look only at them, the point is most likely in this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question