ajax - Why am I getting 'Symfony2 No route found for "GET /module/%3C" ...', when similar calls work
问题描述
I'm getting: this error message:
No route found for "GET /module/%3C" (from "http://site/app_dev.php/module/page")
using the following ajax call:
timeStamp = ( new Date() ).getTime();
$.ajax( {
method : 'POST',
url : 'http://site/app_dev.php/module/page/Delete/' +
timeStamp,
data : formData,
dataType : 'json',
async : true,
cache : false,
contentType : false,
processData : false,
success : function( data ) { ... },
error : function( jqXHR, textStatus, errorThrown ) { ... }
} );
Here is the page route annotation and function definitions that I'm trying to call:
/**
* @Route("/module/page")
* @Route("/module/page/{timeStamp}")
* @Route("/module/page/Delete/{timeStamp}")
*
* @return: page response HTML string, JSON encoded action results or
* JSON encoded error results.
*/
public function pageAction( $timeStamp=NULL ) { ... }
What is strange is that this function is successfully used to produce the page that contains several other similar ajax calls that do work in addition to the one above.
Here is one of the calls that work:
$.ajax( {
method : 'POST',
data : formData,
dataType : 'json',
async : true,
cache : false,
contentType : false,
enctype : 'multipart/form-data',
processData : false,
success : function( data, textStatus, jqXHR ) { ... ),
error : function( data ) { ... }
} );
The primary difference is that the ajax call that fails has an explicit url and the one that works uses the implicit address string of the page being displayed.
I tried the call with and without these two parts in the url, but get the same result either way.
I don't know if this is significant, but when I use the debugger in Chrome, the breakpoint at the first code line in the success function briefly highlights and then the page is replaced with the one displaying the 'No route found ...'
Since, the call uses message: 'POST', why would the error say 'Get' and using the explicit url that includes '/Delete' and '/' + timeStamp, why aren't these shown in the error message?
Incidentally. In the ajax call with the explicit url, I'm adding a timeStamp to prevent a previously cached response from being returned rather than making the actual call to the server to delete the information referenced in the formData object.
In another ajax call that returns the information that is supposed to be deleted by the failing call, I found that even though 'cache: false' was set, the call would return an outdated response from the a previous call if I didn't include the timeStamp in the explicit url, but with the timeStamp included, that case works fine.
解决方案
问题是 html 元素,一个锚标记,它调用包含我认为不起作用的 ajax 的函数,也有一个“href”,它使它自己向服务器请求一个不存在的页面,并且其中包含奇怪的 '%3C' 字符。
所以真正的答案是不要缠在车轴上,一定要检查导致明显问题的一切。
在这种情况下,导致错误消息的调用发生在 ajax 服务器端对正确函数的调用之前,这就是为什么调试器显示即使执行在正确的断点处停止的原因由于显示未找到错误,成功功能控件被“拉走”。
推荐阅读
- php - wordpress 上的连接问题太多,使用数据库缓存,非共享主机
- java - java android应用程序无法使http获取
- javascript - Vue 中的 Spotify Auth:获取 URL 参数
- salesforce - Salesforce 中的触发器测试类
- python - pandas 使用 iloc 获取索引列表的方法?
- c# - Xamarin Android - VpnService 正在阻止所有应用程序
- javascript - 通过消息事件获取 iframe
- python - Python/Bokeh:通过交互式图例隐藏字形时不显示悬停工具
- jmeter - 使用 JMeter 从 JSON 中提取具有相同名称的字段值
- python - 查找 USB 硬盘驱动器的挂载卷和挂载点