2009-07-13 1 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() 호출은 사이트의 루트로 이동합니다. "/ipd/services.aspx/GetActivePatient"로 URL을 변경하면 작동합니다. 모든 호출에 대해이 해결 방법을 구현하는 대신 루트 (/)로 사이트를 이동하려고 할 수 있습니다 ... – 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

관련 문제