데이터를 서버로 POST하고 데이터 세트를 다시 가져 오려고합니다. 내가 대신 돌아오고있는 것은 전체 페이지의 HTML입니다. 및 내 컨트롤러의 작업을 시작하지 않습니다. 그리고 예 - JQuery는 여전히 나에게 혼란 스럽습니다.
내가 현재 가지고있는 코드는 다음과 같습니다 콜백 함수는 트립하고 같은 함수 정의 보이는
function updateNavIndex(pageIndex) {
var filters = $("form").serialize();
var productGroup = $("#valProductGroup").attr('title');
var productType = $("#valProductType").attr('title');
var itemsPerPage = $("#ItemsPerPage").val();
$.ajax({ path: "/CatalogAjaxController/UpdateNavigation"
, type: "POST"
, data: "{ productGroup: " + productGroup + ", productType: " + productType + ", itemsPerPage: " + itemsPerPage + ", pageIndex: " + pageIndex + ", filters: " + filters + "}"
, success: function(data) { handleMenuData(data); }
});
$.ajax({ path: "/CatalogAjaxController/UpdateProducts"
, type: "POST"
, data: "{ productGroup: " + productGroup + ", productType: " + productType + ", itemsPerPage: " + itemsPerPage + ", pageIndex: " + pageIndex + ", filters: " + filters + "}"
, success: function(data) { handleProductData(data); }
});
}
: "데이터는"변수가 페이지의 HTML에있다이 시점에서
function handleMenuData(data) {
$("#navigation ul").remove();
}
그것. (그리고 내가 말했듯이, Action은 실행되지 않았다.) 나는 $ ajax 함수를 직접 호출하지 말고 var 함수 정의를 사용해야한다고 생각하고있다. 예 :
var retrieveMenuData = function(path, productGroup, productType, itemsPerPage, pageIndex, filter, fnHandleCallback) {
$.ajax(path
, type
, { productGroup: productGroup, productType: productType, itemsPerPage: itemsPerPage, pageIndex: pageIndex, filter: filter }
, function(data) { fnHandleCallback(data); });
};
정확하게 정의했는지 또는 올바르게 호출했는지 확실하지 않습니다. 어떤 도움을 주셔서 감사합니다!
아, 좋은 지적은 ... 자바 스크립트에서 JSON을 인용하는 것은 의미가 없다 ... JSON은 결국 Javscript Object Notation이다. – Powerlord
"http://stackoverflow.com/questions/799404/ajax-and-mvc-c"에서 게시물을 사용하고 있으며 "데이터가 정의되지 않았습니다."라는 오류가 계속 발생합니다 - 여기서 데이터는 Controller.Action 메소드. –
같은 내 VAR 함수 정의 lookls : var에 retrieveData2 = 기능 (경로, productGroup, productType, itemsPerPage, pageIndex, 필터, fnHandleCallback) { $ .getJSON (경로 , {productGroup : productGroup, productType : productType, itemsPerPage : itemsPerPage, pageIndex : pageIndex, filter : filter} , 함수 (데이터) {fnHandleCallback (데이터);}); }; 내가 전화를 걸면 오류가 발생합니다. 내 통화는 다음과 같습니다. retrieveData2 ("/ CatalogAjaxController/UpdateNavigation", productGroup, productType, itemsPerPage, pageIndex, filters, handleMenuData (data)); * confused * –