We're using jQuery.ajax() methods to request server data on a number of pages on our MVC 3 web site. These requests are always marked with the 'POST' ajax parameter type and are typically invoked on page load or perhaps on a timer, that is to say, they are not a result of a user action (e.g. a mouse-click).
我们正在使用jQuery.ajax()方法来请求MVC 3 web站点上多个页面上的服务器数据。这些请求总是使用“POST”ajax参数类型进行标记,通常在页面加载或计时器上调用,也就是说,它们不是用户操作的结果(例如鼠标单击)。
When we look at the (Elmah) error log we see a number of entries as follows:
当我们查看(Elmah)错误日志时,我们会看到以下一些条目:
A public action method 'GetMessageStats' was not found on controller 'Inbox.WebUI.Areas.Application.Controllers.StatusController'.
在controller的Inbox.WebUI.Areas.Application.Controllers.StatusController中找不到一个公共操作方法“GetMessageStats”。
The controller action is marked with the [HttpPost] e.g.
控制器动作被标记为[HttpPost]例。
[HttpPost]
public JsonResult GetMessageStats()
{
MessageStatsViewModel model = new MessageStatsViewModel
{
TotalNoMessages = MailDB.GetMessageCount(),
MessagesInQueue = MailDB.GetQueueLength()
};
return Json(model);
}
and here is the invoking client script:
下面是调用客户端脚本:
$(function() {
var $totalMessages = $("#total-messages"),
$queuedMessages = $("#queued-messages");
function getStats() {
$.ajax({
type: "POST",
url: "/Application/Status/GetMessageStats",
dataType: "json",
cache: false,
success: function (data) {
$totalMessages.text(data.TotalNoMessages);
$queuedMessages.text(data.MessagesInQueue);
setTimeout(function() {
getStats();
}, 15000);
},
error: function (xmlHttpRequest, errorMessage, exception) {
throw errorMessage;
}
});
}
getStats();
});
On investigation it appears that some browsers (IE7/IE8, but maybe others) seem to issue a GET request in addition to the required POST request. It is noted that the user interface responds and behaves correctly under these browsers so the POST request is being serviced.
在调查中,似乎一些浏览器(IE7/IE8,但也可能是其他浏览器)除了发出要求的POST请求外,还发出了GET请求。注意,用户界面在这些浏览器下的响应和行为是正确的,因此POST请求正在被服务。
Elmah is reporting the user agent as:
Elmah报告用户代理为:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla / 4.0(compatible;MSIE 6.0;Windows NT 5.1)
Has anyone else seen this problem? If so, have you found a way to avoid it?
有人见过这个问题吗?如果是的话,你找到办法避免它了吗?
Thanks.
谢谢。
4 个解决方案
#1
3
For what it is worth, re: the superfluous GET, I found that there were some toolbars/security services that would 'check' urls to make sure they were valid. I believe it was TrendMicro who had a Web of Trust type plugin that would re-poll sites to examine them for malware.
值得注意的是,re:多余的GET,我发现有一些工具栏/安全服务会“检查”url以确保它们是有效的。我相信是TrendMicro有一个信任类型的网络插件,可以重新调查网站,检查他们的恶意软件。
Have you tried using the shorthand ajax methods, like $.post()? Also, if you're getting data, is there a specific reason you need a POST?
您是否尝试过使用简短的ajax方法,比如$.post()?此外,如果你正在获取数据,是否有什么特别的原因需要发布信息?
If you generate a request through Fiddler or your tool of choice, do you get the same error in the response?
如果您通过Fiddler或您选择的工具生成请求,那么您在响应中是否会得到相同的错误?
#2
0
Apparently this happens when you have another function that is modifying the URL and appending a GET parameter. If that happens then IE has a tendency to send both a GET and POST request.
显然,当您有另一个函数修改URL并附加GET参数时,就会发生这种情况。如果发生这种情况,IE会发送GET和POST请求。
The function could probably be 'ajaxSend' which is the jQuery function that is called before the ajax request is sent.
该函数可能是“ajaxSend”,即在发送ajax请求之前调用的jQuery函数。
The solution would be to not modify the URL directly, but to pass any extra parameters that are need into the request.
解决方案是不直接修改URL,而是将需要的任何额外参数传递到请求中。
Info taken from: http://www.justinball.com/2009/07/08/jquery-ajax-get-in-firefox-post-in-internet-explorer/
信息来自:http://www.justinball.com/2009/07/08/jquery-ajax-get-in-firefox-post-in-internet-explorer/
#3
0
The method that you are using in your javascript code is a GET method. So try removing [HttpPost] from the controller action method.
在javascript代码中使用的方法是GET方法。因此,请尝试从controller操作方法中删除[HttpPost]。
Or to make it a post method, pass post data like this.
或者让它成为post方法,像这样传递post数据。
url: "/Application/Status/GetMessageStats",
data: {},
dataType: "json",
Try this. Not tested..
试试这个。不是测试. .
#4
0
I had similar problem once. The solution for me was to add another setting value:
我曾经遇到过类似的问题。我的解决方案是添加另一个设置值:
processData: false
to the jQuery ajax call.
到jQuery ajax调用。
#1
3
For what it is worth, re: the superfluous GET, I found that there were some toolbars/security services that would 'check' urls to make sure they were valid. I believe it was TrendMicro who had a Web of Trust type plugin that would re-poll sites to examine them for malware.
值得注意的是,re:多余的GET,我发现有一些工具栏/安全服务会“检查”url以确保它们是有效的。我相信是TrendMicro有一个信任类型的网络插件,可以重新调查网站,检查他们的恶意软件。
Have you tried using the shorthand ajax methods, like $.post()? Also, if you're getting data, is there a specific reason you need a POST?
您是否尝试过使用简短的ajax方法,比如$.post()?此外,如果你正在获取数据,是否有什么特别的原因需要发布信息?
If you generate a request through Fiddler or your tool of choice, do you get the same error in the response?
如果您通过Fiddler或您选择的工具生成请求,那么您在响应中是否会得到相同的错误?
#2
0
Apparently this happens when you have another function that is modifying the URL and appending a GET parameter. If that happens then IE has a tendency to send both a GET and POST request.
显然,当您有另一个函数修改URL并附加GET参数时,就会发生这种情况。如果发生这种情况,IE会发送GET和POST请求。
The function could probably be 'ajaxSend' which is the jQuery function that is called before the ajax request is sent.
该函数可能是“ajaxSend”,即在发送ajax请求之前调用的jQuery函数。
The solution would be to not modify the URL directly, but to pass any extra parameters that are need into the request.
解决方案是不直接修改URL,而是将需要的任何额外参数传递到请求中。
Info taken from: http://www.justinball.com/2009/07/08/jquery-ajax-get-in-firefox-post-in-internet-explorer/
信息来自:http://www.justinball.com/2009/07/08/jquery-ajax-get-in-firefox-post-in-internet-explorer/
#3
0
The method that you are using in your javascript code is a GET method. So try removing [HttpPost] from the controller action method.
在javascript代码中使用的方法是GET方法。因此,请尝试从controller操作方法中删除[HttpPost]。
Or to make it a post method, pass post data like this.
或者让它成为post方法,像这样传递post数据。
url: "/Application/Status/GetMessageStats",
data: {},
dataType: "json",
Try this. Not tested..
试试这个。不是测试. .
#4
0
I had similar problem once. The solution for me was to add another setting value:
我曾经遇到过类似的问题。我的解决方案是添加另一个设置值:
processData: false
to the jQuery ajax call.
到jQuery ajax调用。