Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX naming conventions

Tags:

jquery

ajax

php

I have a web app with a lot of files that I call via jQuery. My main scripts reside in the top-level directory, and my ajax scripts reside in /ajax.

Most of the AJAX scripts I write tend to have a single function, and so I name them appropriately (i.e. add_user.php, process_cc_payment.php). But depending on what I'm doing with it, they tend to vary wildly and there's no rhyme or reason to their names. Is there a standard practice for this?

like image 753
Matthew Avatar asked Nov 23 '10 02:11

Matthew


People also ask

What are the naming conventions in JavaScript?

Naming ConventionsVariable and function names written as camelCase. Global variables written in UPPERCASE (We don't, but it's quite common) Constants (like PI) written in UPPERCASE.


2 Answers

There no single standard practice for this, just follow some basic rules (your rules that you and your team follow, this is my general list):

  • Above all do what works for you and your team
  • Keep the names descriptive as possible, but not too verbose
  • I personally try and name them with some sort of convention, for example all payment stuff could be payment_xxxx.php, again do what works for you here
like image 61
Nick Craver Avatar answered Oct 03 '22 00:10

Nick Craver


I would recommend you to organize the methods and put it together.Ex: Have a file for all methods of user (add user,update user,get user,delete user etc..) Use querystring values to discriminate which function to be called.I usually add a handler suffix to the file names and keep it under the handler folder under my Library(Lib) folder

Lib\handlers\userhandler.php

Lib\handlers\coursehandler.php

like image 40
Shyju Avatar answered Oct 03 '22 01:10

Shyju