2013-08-15 1 views
0

웹 사이트에서 일부 데이터를 가져 오려고하는데 먼저 로컬 호스트를 사용하려고합니다. Get 요청은 실패합니다. POST로 변경하면 문제가 없습니다.리소스를 찾을 수 없습니다. HttpGet

Error: The Resource cannot be found. 

컨트롤러 작업 :

[HttpGet()] 
     public ActionResult GetInformation(string id) 
     { 
      Uri uri = new Uri("http://localhost:65076/ShowDetails?id=" + id); 
      HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); 

      request.Method = WebRequestMethods.Http.Get; 
      HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); 
      StreamReader reader = new StreamReader(response.GetResponseStream()); 
      string tmp = reader.ReadToEnd(); 
      response.Close(); 

      return Json(new { data = tmp }); 
     } 

자바 스크립트 기능 : 이것은 GET이기 때문에

function getInformation() { 
    var link = '/Home/GetInformation'; 
    var id = '11111'; 
    $.ajax({ 
     type: 'GET', 
     url: link, 
     data: { id: id }, 
     dataType: 'json', 
     success: function (result) { 
      $.each(result.data, function (item, value) { 
       ... 
      }); 
     }, 
     error: function (result) { 
       ... 
     } 
    }); 
}; 
+1

당신 수하십시오 acti의 Json 생성자에 다음 코드를 추가하십시오. 에. 'JsonRequestBehavior = JsonRequestBehavior.AllowGet' 기본적으로 MVC는 JSON 요청 가져 오기를 허용하지 않습니다. – erdal

답변

2

, 쿼리 문자열에서 데이터 전달 :

function getInformation() { 
    var link = '/Home/GetInformation?id=11111'; 
    $.ajax({ 
     type: 'GET', 
     url: link, 
     dataType: 'json', 
     success: function (result) { 
      $.each(result.data, function (item, value) { 
       ... 
      }); 
     }, 
     error: function (result) { 
       ... 
     } 
    }); 
};