Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP execution - Can I use Ajax method after close connection

I was developing a web application

I am building the PHP part now and I have planned to build the script / AJAX part in the future. like adding sort/category option using AJAX to the application.

Below is how my syntax is

<?php open-connection();?>

    <html> 
         Some html part with sort option
         <script>script part and some AJAX part </script>
    </html>


<?php ob_flush and Close-mysql-connection ?>

will my Ajax /script part works that has access to database depending on the user.

I think after the close connection establishing the ajax will not work. Please guide me.

thanks in advance

like image 727
Yellow and Red Avatar asked Nov 26 '25 05:11

Yellow and Red


1 Answers

An ajax call will open a new HTTP connection by it self. It is no different than an ordinary request to your server in terms of connecting. Bare in mind though, that you need to initialize connections to databases again in the script that is to be called dynamically because, as I said, it is treated as a separate request, which it actually is, therefore you need to re-initialize everything that you need to use.

Best of luck! :P

like image 129
php_nub_qq Avatar answered Nov 27 '25 21:11

php_nub_qq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!