2011-10-04 3 views
5

json 결과에 문제가 있습니다. jquery에서 호출 할 때 성공 함수를 실행하는 대신 파일을 저장합니다. get jquery 요청은 document.ready 함수에서 발생합니다.JsonFile을 반환하는 MVC3 컨트롤러

도움을 주시면 감사하겠습니다.

public ActionResult Locations() 
    { 
     LocationsModel lm = new LocationsModel(); 
     return Json(lm.getPins(), JsonRequestBehavior.AllowGet); 
    } 

나는 또한 시도 : 다음과 같이

public JsonResult Locations() 
    { 
     LocationsModel lm = new LocationsModel(); 
     return Json(lm.getPins(), JsonRequestBehavior.AllowGet); 
    } 

JQuery와는 다음과 같습니다

$.ajax({ 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     url: this.href, 
     data: "{}", 
     dataType: "json", 
     success: function (msg) { getPins_success(msg); }, 
     error: OnError 
    }); 

감사합니다, 크리스

편집 :

결코

그것이 마음 에이 이런. 일단 json 요청을 컨트롤러의 다른 액션으로 옮기고 모든 뷰를로드했습니다. 이제 구문 분석 문제가 있지만 문제는 모두 함께 있습니다.

+2

'AllowGet'과'type : "POST"'? –

답변

1

대신 getJson을 사용해야합니다.

는 당신을 위해 그것을는 다음과 같습니다

$.getJSON(this.href, function (msg) { getPins_success(msg); }); 

이것은 당신이 JSON으로 반환 된 데이터를 분석 할 수있게된다.

관련 문제