$ .ajax不返回数据 [英] $.ajax not returning data

查看:173
本文介绍了$ .ajax不返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据回传到服务器并获取数据集.相反,我得到的是整个页面 AND 的HTML,它没有在Controller中启动Action.是的-JQuery仍然让我感到困惑.

I am trying to POST data back to the server and get a dataset back. What I am getting back instead is the HTML for the whole page AND it is not kicking off the Action in my Controller. And yes - JQuery is still confusing to me.

我当前拥有的代码是:

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); }
    });
}

回调函数跳闸,函数定义如下:

The callback function is tripping and the function definition looks like:

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

在这一点上,数据"变量具有页面HTML. (并且就像我说的那样,Action并没有触发.)我在想我不应该直接调用$ ajax函数,而应该使用var函数定义.像这样:

At this point the "data" variable has the Page HTML in it. (And like I said, the Action did not fire off.) I am thinking that I should not be calling the $ajax function directly but using a var function definition. Something like:

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); });
};

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

I'm not sure if I have it defined correctly or how to call it correctly. ANy help is appreciated!

推荐答案

此外,您在其中也有一些奇怪的引号..data:的语法更像是这样:

also, you've got some odd quotes in there.. the syntax for data: is more like this:

$.ajax({
    type: "POST",
    url: "bin/login.php",
    data:{data1: var1,data2: var2},
    success: function(data) {
        }
     });

这篇关于$ .ajax不返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆