2009-07-13 3 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/wの差はIIS6でアプリケーションとして有効になっているサブフォルダ(/ IPD)に位置しているアプリケーション/部位です。

Firebugで応答を表示すると、この呼び出しで「404 Page Not Found」エラーが表示されます。

感謝しています。

+0

を見てください。 – ChrisP

+0

eu-ge-neの答えは、いくつかの研究につながりました。問題は、サイトが/ ipdの子フォルダにあるため、サーバーへのすべての呼び出しに "/ ipd"という接頭辞が付いていることです。明らかに、/ ipdフォルダがアプリケーションとしてマークされていても、$ .ajax()呼び出しはサイトのルートに行きます。 URLを「/ipd/services.aspx/GetActivePatient」に変更すると機能します。すべての呼び出しに対してこの回避策を実装するのではなく、サイトをルート(/)に移動しようとする可能性があります。 – ChrisP

答えて

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, 

また、単に$アヤックス()の呼び出しは、.jsファイルにはJQueryを使用している明確にするStephen Walther - ASP.NET MVC Tip #45 – Use Client View Data

+0

このURL定義は.jsファイルのJQuery $ .ajax()呼び出しの一部です。サーバサイドのスクリプト<% ... %>が処理されるとは思わない。 – ChrisP

関連する問題