0

I get the user's ip address and then send a request to the server to learn the country.

How can I make my php function make a request after the page content is loaded.

  • in short, you can't. If you want things to run in the background you'll need to look into `ajax` : https://www.w3schools.com/php/php_ajax_intro.asp#:~:text=AJAX%20%3D%20Asynchronous%20JavaScript%20and%20XML,without%20reloading%20the%20whole%20page. – imposterSyndrome Sep 17 '20 at 15:32
  • Does this answer your question? [using jquery $.ajax to call a PHP function](https://stackoverflow.com/questions/2269307/using-jquery-ajax-to-call-a-php-function) – imposterSyndrome Sep 17 '20 at 15:37
  • 1
    You have two ways: you can do it at the front end side by using ajax as stated by @jameson2012 above, to call a script just after the page is loaded. You can also do it at the backend side by using output buffering (see here https://stackoverflow.com/q/15273570/14066311) – Prince Dorcis Sep 17 '20 at 16:10
  • It depends on what you mean by loaded: 1) PHP ends it's work as soon as page is formed and passed to the users' browser. 2) Browser loads the page 3) JavaScript works with the page that resides on the side of a user. If you want to activate a request to the server after the page is loaded to userm just use Jquery $(function() { }) structure, that will make sure your code is executed after everything is loaded. Inside {} put ajax request to the server. Store web variables if you need in hidden inputs with ids on the page. – Undry Sep 17 '20 at 17:29

0 Answers0