V
V
vaflya2015-10-18 14:19:30
PHP
vaflya, 2015-10-18 14:19:30

How to load ajax pages using php routing?

Good afternoon. "Routing" is made on the site (Through the index.php file, if I'm not mistaken, it's called the controller).
So, in the .htaccess file

RewriteEngine on
RewriteBase /
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^js/(.*)$ js/$1 [L]
RewriteRule ^img/(.*)$ img/$1 [L]
RewriteRule ^css/(.*)$ css/$1 [L]
RewriteRule ^photos/(.*)$ photos/$1 [L]
RewriteRule ^.*$ [NC,L]
RewriteRule ^.*$ index.php [NC,L]
AddDefaultCharset utf-8
AddType 'text/html; charset=utf-8' .html .htm .shtml


Accordingly, all requests are redirected to index.php. But if you need to load via ajax, then you need to do additional. conditions in index.php or create ajax.php in the root and load requests through it?

And actually tell me how to do in .htaccess so that ./ajax.php is not redirected to index.php.

Here I thought again. Do everything through index.php? Like,
index.php - give the title plus the content
index.php?get=file - give only the content

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2015-10-18
@vaflya

Through the index.php file, if I'm not mistaken, the controller is called

Usually it is called "entry point" (entry point).
If you're doing a single entry point, then why make ajax.php?
Obviously, also indicate in the router which code will be responsible for responding to AJAX requests.
index.php - get title plus content
index.php?get=file - get content only

You come up with some perversions and invent bicycles that ride on crutches. At the same time, you are afraid of frameworks.
From your other question:
I won't use frames, because This is a hobby for me and I do not pursue any goals
If you do for yourself - does this mean that you need to do badly? The framework will give you a certain backbone and solve a bunch of problems that you yourself will solve either for a long time or badly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question