gpt4 book ai didi

jquery - $.ajax 不返回数据

转载 作者:行者123 更新时间:2023-12-01 07:02:59 24 4
gpt4 key购买 nike

我正在尝试将数据发布回服务器并获取数据集。相反,我返回的是整个页面的 HTML 并且,它没有启动我的 Controller 中的操作。是的 - 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); }
});
}

回调函数正在触发,函数定义如下:

function handleMenuData(data) {
$("#navigation ul").remove();
}

此时,“data”变量中已包含页面 HTML。 (就像我说的,操作没有触发。)我认为我不应该直接调用 $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); });
};

我不确定我是否正确定义了它或如何正确调用它。感谢任何帮助!

最佳答案

解决方案可能非常简单。

您正在使用 path: ,它应该有 url:

来源:jQuery.ajax options list

关于jquery - $.ajax 不返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/830520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com