2009-07-13 69 views
1

.js文件中的以下JQuery $ .ajax()调用在本地工作,但在部署到我的ISP时无法工作。

$.ajax({ 
    type: 'GET', 
    url: 'Services/GetActivePatient', 
    async: false, 
    dataType: 'json', 
    cache: false, 
    success: function(pt) { 
    Alert(pt); 
    }, 
    error: function(xhr, ajaxOptions, thrownError) { 
    alert('Error loading active patient' + 'XHR:' + xhr + ' OPTIONS:' + ajaxOptions + ' ERROR:' + thrownError); 
    } 
}); 

我的路线是:

routes.MapRoute(
     "aspx", 
     "{controller}.aspx/{action}/{id}", 
     new { action = "Index", id = "" } 
    ); 

    routes.MapRoute(
     "Default", 
     "{controller}/{action}/{id}", 
     new { controller = "Home", action = "Index", id = "" } 
    ); 

    routes.MapRoute(
    "Root", 
    "", 
    new { controller = "Home", action = "Index", id = "" } 
); 

的差异瓦特/ ISP是应用程序/站点位于子文件夹(/ IPD),它在IIS6的应用程序中启用。

在此调用中,当我在Firebug中查看响应时,出现“404 Page Not Found”错误。

任何想法赞赏。

+0

只是为了澄清$。阿贾克斯()调用在.js文件中使用JQuery。 – ChrisP 2009-07-13 21:38:24

+0

eu-ge-ne的回答下面导致了一些研究,问题是因为该站点位于/ ipd子文件夹中,“/ ipd”被加到服务器的所有调用前面。显然,即使/ ipd文件夹被标记为应用程序,$ .ajax()调用将转到网站的根目录。 将url更改为“/ipd/services.aspx/GetActivePatient”的作品。而不是为所有的调用实现这个解决方法,我可能会尝试将网站移动到根(/)... – ChrisP 2009-07-13 22:26:49

回答

1

尝试改变:

url: 'Services/GetActivePatient', 

url: '<%= Url.Action("GetActivePatient", "Services") %>', 

// returns /ipd/Services/GetActivePatient on the ISP 
// and /Services/GetActivePatient on local server 

更新:

如果你有单独的JS文件,然后使用这样的事情在你的视野:

<script type="text/javascript"> 
    var Services_GetActivePatient_Url = '<%= Url.Action("GetActivePatient", "Services") %>'; 
</script> 

然后JS:

url: Services_GetActivePatient_Url, 

也期待在Stephen Walther - ASP.NET MVC Tip #45 – Use Client View Data

相关问题