Link to home
Start Free TrialLog in
Avatar of Ridgejp
RidgejpFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Mysqli_query() & Ajax

Hi,

If I'm using an Ajax command to run a Mysqli_query in another PHP file - can I return the results of the Mysqli_query into the page I'm working in?

J
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Yes!  It's done all the time and it's quite easy.

Here is the most basic and simplified example I can find for a jQuery "Hello World" script.
https://www.experts-exchange.com/articles/10712/The-Hello-World-Exercise-with-jQuery-and-PHP.html

Here is an article about MySQL, and while it's mostly about how to get off the obsolete MySQL extension, it gives examples of how to run a query and retrieve a results set.  You can send the results to the client browser by using techniques shown in the jQuery Hello World.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

When you get started building the server-side script that responds to the AJAX request, you probably want to use GET-method requests.  If you do that, you can test your scripts from the browser, using URL parameters and seeing the browser output (use "view source").  This makes testing and debugging very easy.  Once the server-side script works correctly and gets the right information from the database, you can add the client-side script that makes the AJAX request and adds the returned data to the browser display.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial