2009-05-06 95 views
1

我正在尝试将数据发送回服务器并获取数据集。我回来的是整个页面的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); } 
    }); 
} 

回调函数跳闸和函数的定义是这样的:

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

此时的“数据”变量在页面HTML它。 (就像我说的,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); }); 
}; 

我不确定是否正确定义了它,或者如何正确调用它。任何帮助表示赞赏!

回答

2

也,你在那里得到了一些奇怪的报价。对于data:语法更像是这样的:

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

啊,好点...在javascript中引用JSON并没有多大意义...... JSON毕竟是Javscript对象表示法。 – Powerlord 2009-05-06 16:55:53