B
B
bozhenov_mikhail2020-05-02 10:24:30
PHP
bozhenov_mikhail, 2020-05-02 10:24:30

Is it possible to receive a request from a JS script?

I have a page bum.htmlwhere there are only tags script, and inside the JS script itself.
So, when I request this page, I send another request with AJAX.

For example, there is a page zapros.php
There I send a request like this: file_get_contents('https://site.com/bum.html');
The page bum.htmlcontains an ajax request to a site.

But nothing happens when file_get_contents()you just go to the page - it works.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-05-02
@sergiks

The problem is understanding where what is being executed.
PHP is executed on the server.
HTML is processed in the browser and JavaScript is executed in it (in the browser).
file_get_contents()gets just a line of text. In order for the JavaScript contained in it to be executed, a browser or something that imitates it is needed.
To execute JavaScript on the server, use NodeJS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question