2016-08-19 4 views
0

다음 문제가 있습니다. .cshtml 파일에 대한 ajax 호출을 작성 중입니다 ... localhost에서 제대로 작동하지만 서버에 업로드하면 "금지됨 403) "Ajax - .cshtml 호출시 오류가 발생했습니다.

이 내 아약스 호출입니다 :

$.ajax({ 
    type: "GET", 
    url: "~/MyProcessPage.cshtml", 
    contentType: "application/x-www-form-urlencoded", 
    data: { id: 1 }, 
    crossDomain: true, 
    success: function (res) { 
     console.log(res); 
    }, 
    error: function (res) { console.log(res); }, 
    dataType: 'json' 
}); 

이 내 C# 코드입니다 :

if (HttpContext.Current.Request.HttpMethod == "GET") 
{ 
    var id= Convert.ToInt32(Request.QueryString["id"]); 
    Response.Write(id); 
}  

내가 면도칼을 사용하지만, MVC를 사용하지 않는주의하십시오!

감사합니다.

+2

당신을 위해이 페이지로드 하는가를 변경 놈이야? – serhiyb

+1

그럼 로컬 호스트에서 작동한다면 먼저 서버 구성, 폴더 사용 권한, 허용 된 파일을 요청하고 응답 할 수 있습니다. 구성 문제와 같은 것 같습니다. –

+0

왜 crossDomain : true입니까? – derloopkat

답변

1

은 아마 당신은 브라우저에`... \ MyProcessPage.cshtml`를 입력하여 AJAX없이 URL

$.ajax({ 
    type: "GET", 
    url: '@Url.Content("~/MyProcessPage.cshtml")', 
    contentType: "application/x-www-form-urlencoded", 
    data: { id: 1 }, 
    crossDomain: true, 
    success: function (res) { 
     console.log(res); 
    }, 
    error: function (res) { console.log(res); }, 
    dataType: 'json' 
}); 
+0

예, ajax 호출이 외부 .js 파일이 아닌 다른 .cshtml 파일 내부에 있다고 가정합니다. – derloopkat

+0

그 점은, 아약스 호출은 js 파일에있다 – CHACO

+0

나는 MVC를 위해 @Url ir를 추측한다. – CHACO

관련 문제