如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])

我有一个大项目需要通过Ajax调用处理多个函数,到目前为止我使用不同的文件来处理每个函数调用。 我知道必须有更好的方法来通过API处理请求

那么在结构方面设计这样一个API的标准做法是什么?

谢谢!


I have a large project that requires multiple functions to be processed through Ajax calls, so far I am using different files to handle each function call. I know there's got to be a better way to handle the requests through an API

And what would be a standard practice for designing such an API in terms of structure?

Thanks!


原文:https://stackoverflow.com/questions/28758882
2024-04-24 19:04

满意答案

如您所知,默认模块中的控制器名称不需要前缀(Ex: SomeController ),而非默认模块中的控制器需要前缀(例如: Admin_SomeController )。

在基于模块的应用程序中,我个人发现使用模块名称为所有控制器添加前缀更加一致。 这是作为一个问题提交的,并通过添加前端控制器设置prefixDefaultModule 显然在版本1.5中 prefixDefaultModule

因此,在application/configs/application.ini ,您可以添加:

resources.frontController.prefixDefaultModule = true

我一直都在使用它,并认为它很棒。 ;-)


As you note, controller names in the default module do not require prefixing (Ex: SomeController), while controllers in non-default modules require prefixing (Ex: Admin_SomeController).

In module-based app, I personally find it more consistent to prefix all controllers with the module name. This was filed as an issue and fixed in apparently in version 1.5 by adding a front controller setting prefixDefaultModule.

So, in application/configs/application.ini, you could add:

resources.frontController.prefixDefaultModule = true

I use it all the time and think it's great. ;-)

相关问答

更多

lxml XMLSyntaxError:未找到命名空间的默认前缀(lxml XMLSyntaxError: Namespace default prefix was not found)

好的,所以我终于明白了发生了什么事。 在清理使用过的元素之后,我正在清理所有元素,包括根节点。 根节点是具有默认名称空间前缀的节点,适用于该根中的所有节点。 由于我清除了我的根节点,默认的名称空间前缀不再是其子元素的nsmap的一部分。 以前的版本似乎是宽容的,但最新版本在这个意义上更严格。 不清除根元素,直到我读完xml为我做了窍门。 Ok, so I finally figured out what was going on. Following a good advice to clean ...

XSLT 2.0灵活,具有相同URI的默认或不同的前缀命名空间(XSLT 2.0 flexible with default or different prefixed namespace of the same URI)

更换 <xsl:template match="*"> <xsl:element name="{name()}"> <xsl:apply-templates select="@* | node()"/> </xsl:element> </xsl:template> <!-- attribute template to copy attributes over --> <xsl:template match="@*"> <xsl:copy> ...

在命名空间Kubernetes中创建入口控制器(Create ingress controller in namespace Kubernetes)

入口资源必须与后端服务位于同一名称空间中。 这可以是任何命名空间不需要与控制器相同 The ingress resource must be in the same namespace as the backend service. This can be any namespace doesn't need to be the same as the controller

Yii - 从URL中消除模块的默认控制器ID(Yii - Eliminate default controller ID for a module from URL)

这有点棘手,因为操作部分可能被视为控制器,或者您可能指向现有控制器。 但是,您可以使用自定义URL规则类来逃避这一点。 这是一个例子(我测试过它似乎工作得很好): class CustomURLRule extends CBaseUrlRule { const MODULE = 'mymodule'; const DEFAULT_CONTROLLER = 'default'; public function parseUrl($manager, $request, $pathInfo...

默认模块中控制器的命名空间/前缀(Namespace / Prefix of Controller in Default Module)

如您所知,默认模块中的控制器名称不需要前缀(Ex: SomeController ),而非默认模块中的控制器需要前缀(例如: Admin_SomeController )。 在基于模块的应用程序中,我个人发现使用模块名称为所有控制器添加前缀更加一致。 这是作为一个问题提交的,并通过添加前端控制器设置prefixDefaultModule 显然在版本1.5中 prefixDefaultModule 。 因此,在application/configs/application.ini ,您可以添加: r...

必须在未指定默认命名空间时使用前缀[duplicate](must be used with a prefix when a default namespace is not specified [duplicate])

至于我已经理解了这个问题。你已经将方法定义为静态所以调用它与类名完全没问题,你错过的一件事就是你应该在那里use scriplet 。 <input type="hidden" name="" id="Rcept_<%=i%>" value='<%=QStr.str_hl( incidentTpEtt.rceptCtts)%>'> 为了能够使用EL,您必须在Session,Request或Page等范围之一中定义实例,然后才能使用它。 注意: - 您还应该在调用str_hl方法之前定义实例inci...

MVC 4路由前缀和Action url生成问题(MVC 4 route prefix and Action url generation issue)

这是您正在创建的区域吗? 如果是这样的话,下面的东西会起作用 @Url.Action("Action", "Controller", new { Area = "Test1" }, null) 下面的区域指南如果此链接被破坏,简单的谷歌就足够了 http://www.itorian.com/2013/10/area-in-mvc-5-with-example-step-by-step.html Is it an area you are creating? if so something lik...

没有使用默认命名空间的XSL输出XML没有前缀?(XSL output XML with no prefix without using the default namespace?)

您可以做的一件事是在变量中捕获XSL的整个结果,然后在结尾处删除其前缀: <stylesheet version="2.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:p="http://api.example.com"> <output method="xml" indent="yes"/> <template match="/"> <variable name="r...

如何禁用特定模块的错误控制器(How to disable error controller for a specific module)

使用以下方法可以禁用特定模块的错误处理程序。 在这个例子中,我将调用你的RESTful模块rest 。 首先,在您的应用程序中创建一个新插件。 例如,这将是Application_Plugin_RestErrorHandler 。 将以下代码添加到application/plugins/RestErrorHandler.php class Application_Plugin_RestErrorHandler extends Zend_Controller_Plugin_Abstract { ...

在lxml中定义默认命名空间(未加前缀)(Define default namespace (unprefixed) in lxml)

此XSL转换从content删除所有前缀,同时维护根节点中定义的名称空间: import lxml.etree as ET content = '''\ <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE html> <h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ml="http://foo"> <h:head> <h:title>MathJax Test Page</h:tit...

相关文章

更多

ajax数据安全的问题

我在一个网页中使用jquery里的ajax函数做ajax效果,一般会按照参数格式填写url(还有其他参 ...

AJAX JSON 乱码

网上下了一个JS、功能是把FORM里的内容序列化为JSON、用AJAX方式提交到后台 JS比较小巧 ...

AJAX问题

我的问题是这样 两个下拉框 区县 &lt;/td&gt; &lt;td width=&quot; ...

ajax请求问题,到底哪里错了

$(function(){ alert(&quot;预加载...&quot;); $(&quot; ...

图解全文检索SOLR的酷应用[Ajax Solr]

Ajax Solr 是一个使用客户端Javascript库实现的基于Solr的应用库,提供了丰富的应用 ...

传智播客王兴魁老师AJax视频教程

如果您没有javaweb和javascript基础,强烈建议您先看传智播客张孝祥老师录制的javawe ...

Ajax彻底研究-视频教程

PHP学习一本通.pdf PHP公益培训第3部-064-ajax长轮询完成咨询功能.wmv PHP公益 ...

ajax跨域请求的解决方案

一直打算改造一下自己传统做网站的形式。 我是.Net程序员,含辛茹苦数年也没混出个什么名堂。 最近 ...

最近遇到一个Ext.Ajax.request的奇怪问题

最近在学Extjs,照着视频做了一个提交数据并且添加store的demo,却遇到一个奇怪的问题:添加第 ...

[IT教程网]Ajax和jQuery基础入门视频[已经完结]

视频介绍: 本视频是Ajax和jQuery基础入门视频,该视频针对接触过javaScript基础 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本