jQuery的阿贾克斯后 - 404错误 [英] jQuery Ajax post - 404 error
本文介绍了jQuery的阿贾克斯后 - 404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我张贴到ActionMethod检索一些客户数。后工作正常,从我的本地机器。当部署到另一台服务器的抛出404错误。我的职位是如下。我不知道为什么,这已停止工作。
VAR urlStr =/项目/ ItemCount中/;
jQuery.ajax({
键入:POST,
数据类型:JSON,
网址:urlStr,
异步:假的,//等待的结果返回...
成功:函数(DocData){
window.currentCount = DocData [0];
window.maximumAllowed = DocData [1];
},
缓存:假的,
错误:函数(请求,状态,错误){
警报(request.responseText);
}
});
&其中; HttpPost()> _
功能ItemCount中()作为JsonResult
昏暗的项目方式列表(MyItems中)= GetItems()
昏暗总为整数=项目.Count之间
昏暗最大值= 5
昏暗的数据作为新的ArrayList
Data.Add(TotalDocs)
Data.Add(MaxDocs)
返回JSON(数据)
端功能
解决方案
可能在另一台机器上部署了应用程序的虚拟目录,并让你在使用的绝对URL没能找到。
尝试使用这个code,而不是
VAR urlStr ='<%:Url.Content(〜/项目/ ItemCount中)%>';
I'm posting to an ActionMethod to retrieve some customer counts. The post works fine from my local machine. When deployed to another server its throwing 404 errors. My post is below. I'm not sure why this has stopped working.
var urlStr = "/Items/ItemCount/";
jQuery.ajax({
type: 'POST',
dataType: 'json',
url: urlStr,
async: false, //wait on the result to be returned...
success: function (DocData) {
window.currentCount = DocData[0];
window.maximumAllowed = DocData[1];
},
cache: false,
error: function (request, status, error) {
alert(request.responseText);
}
});
<HttpPost()> _
Function ItemCount() As JsonResult
Dim Items As List(Of MyItems) = GetItems()
Dim Total As Integer = Items .Count
Dim Max = 5
Dim Data As New ArrayList
Data.Add(TotalDocs)
Data.Add(MaxDocs)
Return Json(Data)
End Function
解决方案
Probably on the other machine you have deployed the application in a virtual directory and so the absolute url you're using could not get found.
Try to use this code instead
var urlStr = '<%: Url.Content( "~/Items/ItemCount" ) %>';
这篇关于jQuery的阿贾克斯后 - 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文