简体   繁体   English

AJAX命名约定

[英]AJAX naming conventions

I have a web app with a lot of files that I call via jQuery. 我有一个Web应用程序,其中包含许多我通过jQuery调用的文件。 My main scripts reside in the top-level directory, and my ajax scripts reside in /ajax. 我的主要脚本位于顶级目录中,而我的ajax脚本位于/ ajax中。

Most of the AJAX scripts I write tend to have a single function, and so I name them appropriately (ie add_user.php, process_cc_payment.php). 我编写的大多数AJAX脚本往往只有一个功能,因此我给它们起了适当的名称(即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? 是否有标准做法?

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 我亲自尝试,并用某种约定的他们的名字,例如所有的支付的东西可能是payment_xxxx.php ,再做什么,你在这里工作

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 我建议您组织这些方法并将其放在一起。例如:对于用户的所有方法(添加用户,更新用户,获取用户,删除用户等)都有一个文件。使用查询字符串值来区分要调用哪个函数。我通常在文件名后添加一个处理程序后缀,并将其保留在我的Library(Lib)文件夹下的handler文件夹下。

Lib\\handlers\\userhandler.php 库\\ handlers \\ userhandler.php

Lib\\handlers\\coursehandler.php 库\\ handlers \\ coursehandler.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM