Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is considered a "best practice" for the design of a set of PHP scripts which service AJAX requests?

I am designing a website which will query a simple MySQL database using AJAX calls to PHP scripts.

I have looked into frameworks which achieve this but I'm looking for a lighter weight solution and so am rolling my own. At present I have all AJAX calls hitting a single script, which then calls further functions based on the content of POSTed variables. Those functions return objects or throw exceptions, and in my main script I either return a JSON encoded version of the object or catch the exceptions and return a JSON encoded "error object".

Does this approach sound ok or not? If not, what is best practice in this scenario?

like image 408
Dutts Avatar asked Nov 30 '10 12:11

Dutts


1 Answers

on the serverside i would reommend a restful approach.

and for the client side javascript i would recommend jQuery ($().ajax())

and it probably would't hurt to code after the principles of MVC

like image 114
netbrain Avatar answered Oct 18 '22 21:10

netbrain