AJAX 站点的文件结构/架构?

发布于 2024-07-08 07:01:17 字数 247 浏览 8 评论 0原文

我正在使用 ajax 构建一个站点,并尝试决定将为 ajax 请求提供数据的文件放置在哪里。

例如,我将有一个 .js 文件,该文件可以包含在将创建国家/州选择框的页面中。 我会将 .js 文件放在 /inc/js 下。

但是,我不确定要将根据所选国家/地区提供状态数据的 ajax 文件放在哪里。 我可以将它放在它支持的文件旁边,为 ajax 数据请求文件创建一个文件夹等。

您如何保持 ajax 请求按文件组织?

I'm building a site using ajax and am trying to decide where to put the files that supply the data for the ajax requests.

For example, I am going to have a .js file that can be included in a page that will create country/state select boxes. I will have the .js file under /inc/js.

However, I am not sure where I want to put the ajax file that supplies the state data based on the country selected. I could put it next to the file it supports, make a folder for ajax data request files, etc.

What do you do to keep your ajax requests organized by file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∝单色的世界 2024-07-15 07:01:17

如果您计划使用模型-视图-控制器体系结构,那么您可以将 ajax 处理程序脚本放置在您维护站点的其余控制器脚本的位置。

例如:

/application
    /default
        /controllers
            index.php
            index.ajax.php
       /views
         index.tpl
         index.ajax.tpl
    /admin

使用这样的模型,您可以自由决定是为 ajax 调用创建处理程序脚本更有意义,还是将 ajax 调用的处理程序脚本集成到其他现有控制器脚本中更有意义。

If you're planning on using a Model-View-Controller architecture, then you would place your ajax handler scripts where you maintain the remainder of the your controller scripts for the site.

For example:

/application
    /default
        /controllers
            index.php
            index.ajax.php
       /views
         index.tpl
         index.ajax.tpl
    /admin

Using a model like this, it leaves you free to decide whether it makes more sense to create handler scripts for your ajax calls or to integrate the handler scripts for your ajax calls into the other, existing controller scripts.

也只是曾经 2024-07-15 07:01:17

创建一个单独的站点(同一服务器或另一服务器上),该站点仅充当为您的请求生成输出的 REST 服务。
当您使用 AJAX 时,您本质上是在使用已发布的 Web 服务。

Create a separate site (same server or on another) that will serve only as a REST service generating output for your requests.
When you work with AJAX you are in essence consuming published web services.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文