0

So I need to make 3 tabs with query (got this part down), but each of them needs to retrieve filter-able data through an Ajax request. Basically the page is setup with a static div on the left with the filter in it, and then on the right the tabs change according to which one you pick.

I'm just wondering what would be the best method of grabbing the ajax content and putting it into each tab?

I hope I made my question clear.

4

1 回答 1

1

如果我正确理解您的问题,这应该很简单。例如,假设您要检索一个静态网页并将该网页的所有内容插入到您的容器 div 中...

$('#tab1').click(function(){
    //Fetch a webpage (via GET) and load into 'result'
    $.get('/path/to/stuff.htm',function(result){
        //Replace content of container with result
        $('#containerDiv').html(result);
    });
});

真的就是这么简单。如果您需要结果的一部分(例如从 XMLRPC 请求中提取 CDATA),那么您可以简单地将结果作为 jQuery 对象加载,找到元素,然后加载它......就像这样......

$('#tab1').click(function(){
    //Fetch a webpage (via GET) and load into 'result'
    $.get('/path/to/stuff.htm',function(result){
        //Make result a jQuery obj
        result = $(result);
        //Replace content of container with result
        $('#containerDiv').html(result.find('mycdata').text());
    });
});

我还应该注意 - 如果您有一个包含在 CDATA 中的 XML 结果,请始终将其读取为 .text() ,即使您将其作为 html 插入也是如此。如果结果未包含在 CDATA 中,则将其读取为 .html()。

更新:如果您需要向服务器发送额外数据(例如排序 ASC 或 DESC),您可以这样做...

$('#tab1').click(function(){
    //Fetch a webpage (via GET) and load into 'result'
    $.get(
        '/path/to/service', 
        { sort:'ASC', startDate:'2012-04-01', endDate:'2012-04-08'}, 
        function(result){
            //Replace content of container with result
            $('#containerDiv').html(result);
        }
    );
});
于 2012-04-10T21:00:48.767 回答