2009-07-13 70 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

相關問題