DEV Community

Discussion on: PHP & MySQL AJAX example Using jQuery

Collapse
williamstam profile image
William Stam • Edited on

And if a user presses enter while in the form it won't trigger, why not just do a $(document).on("submit","#form",function.... Instead of submit form. Same for reset. Using string concat for the listing is also meh. Overall seems like you rather new to this? If your project doesn't use jQuery for other things then you shouldn't add it just for this. (I'm a long time fan of jQuery but I can't with good concious recommend it any more with how good js has become) (that PHP is a SQL injection waiting to happen, use pdo and prepared statements rather, mysqli is on its way out)

Might also be slightly better to split the get records thing into 2, a render and a fetcher function. Then on initial page load pass the records to the render (json_encode) and in your php have an if header is Ajax then return Json encodeed data else return whole html thing. So you only load the html thing once but every Ajax request to the same page only returns the Json. (This stops a flicker of the page while it has to execute a 2nd request just to get the data in, to load a page)

Collapse
codeanddeploy profile image
codeanddeploy Author

Thank you for your suggestion appreciated.