Calling AJAX / jquery in the middle of PHP code

-4

I have a PHP code structure and, within it, I want to automatically call a $.get AJAX to another PHP page.

Example:

<?php $cod = 1; $mod = 2; $text = 3; 
como chamar um ajax automaticamente aqui, sem ter que clicar em botão algum, conforme exemplo abaixo:
echo "<script type='text/javascript'>
    $.get('../print.php?cod =$cod&mod=$mod&text=text');
</script>"
//continuo com o código php
$bla = 1; $bla2 = 2; etc..... '

In other words, in the middle of my script PHP I want to call via AJAX another script that will send another routine and continue in my page routine mother.

I do not know if I was clear, but I need help.

    
asked by anonymous 26.10.2017 / 01:07

1 answer

0

The purpose of ajax is to make an asynchronous request, in cases where you depend on user data and / or load information only when necessary, without having to refresh the page completely. And it is mandatory that to be an ajax this call is made by the front language, and is only executed after the page has already been set up by PHP.

I believe what you wanted to do and just include more code to process on the server, just give an include of the PHP file you want to run.

Remember that unlike Javascript, PHP is a synchronous language and will only run the next command when the previous one is not possible to do a php ajax to php.

I hope I have helped.

    
27.10.2017 / 15:28