jQuery的Ajax调用404 JsonResult控制器方法结果的IIS6 [英] jquery ajax call to JsonResult controller method results in 404 on IIS6

查看:206
本文介绍了jQuery的Ajax调用404 JsonResult控制器方法结果的IIS6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天早上已经拉我的头发试图弄清楚这一点。

I've been pulling my hair out this morning trying to figure this out.

我有一个简单的jQuery JSON请求到我的控制器上的jsonresult行动。当我在我的本地机器(IIS7)上运行它,它工作正常。当我部署到开发计算机运行的IIS6,我得到一个404错误。

I have a simple jquery json request to a jsonresult action on my controller. When I run this on my local machine (IIS7), it works fine. When I deploy to a dev machine running IIS6, I get a 404 error.

脚本:

$(function() {
            $('#search').click(function() {
                var zip = $('#zip').val();
                $.ajax({
                    type: "GET",
                    url: "/Customer/GetCityStateFromZip",
                    data: { zipcode: zip },
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        $("#stateList").setCityState(msg);
                    }
                });
            });
        });

控制器:

public JsonResult GetCityStateFromZip(String zipcode)
        {
            List<CityState> list = new List<CityState>();
            foreach (var item in dt)
            {
                list.Add(new CityState(){City = item.City, StateCode = item.StateCode, StateName = item.StateName});
            }
             return this.Json(list);
        }

请求数据:

GET /Customer/GetCityStateFromZip?zipcode=85215 HTTP/1.1
Host: mydevserver
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Accept: application/json, text/javascript, */*
Accept-Language: en-us,es-mx;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://mydevserver/Customer/Entry

响应数据:

HTTP/1.1 404 Not Found
Date: Wed, 30 Jun 2010 18:01:06 GMT
Content-Length: 1635
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET

在运行IIS6我的开发服务器,我设置了通配符映射(C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\ ASPNET_ISAPI.DLL),并有确认文件是否存在未

On my dev server running IIS6, I have set a wildcard mapping (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll) and have the "Verify that file exists" unchecked.

我的MVC现场工作的所有其他方面就好了。我使用jQuery所有的地方(验证,动画等)和工作的罚款。我似乎无法摆脱这一阿贾克斯问题。

All other aspects of my MVC site work just fine. I'm using jquery all over the place (validation, animation, etc) and that's working fine. I just can't seem to get beyond this ajax issue.

有没有办法,我需要解决的IIS6机上其他一些设置或映射问题?也许IIS6不知道如何路由这个请求?

Is there some other setting or mapping issue that I need to address on the IIS6 machine? Perhaps IIS6 doesn't know how to route this request?

推荐答案

好吧,我借助想通了从another SO帖子

Alright, I figured it out with the help from another SO post.

问题是与URL传递。这是一个从我的机器明显不同,和服务器I部署。我很尴尬,我没有想到这一点。

The problem was with the URL being passed. It's obviously different from my machine, and the server I deployed to. I'm embarrassed that I didn't think about this.

我从这个改变了$就调用:

I changed the $.ajax call from this:

url: "/Customer/GetCityStateFromZip"

要这个,这是使用Url.Action正确的完整路径:

To this, which is using Url.Action to the correct full path:

var url = '<%= Url.Action("GetCityStateFromZip","Customer") %>';
url: url 

和一切都很好。

这篇关于jQuery的Ajax调用404 JsonResult控制器方法结果的IIS6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆