2013-05-01 63 views
-1

這裏是我的前一個問題的HTML:Filter new content to only display specific divs複製變量內外部鏈接

我想獲得和來自外部網頁,複製變量裏面的一些內容。 要執行它,我使用jquery.get函數。

// This code is adding to the div the content 
$('.result').html(data); 

我想保存一個變量裏面的內容才能夠得到的只是,我想

$.get('ajax/test.html', function(data) { 
      // Add to the <div class="result"> the html of data 
      $('.result').html(data); 
      // I would like some thing like this 
      var result = the html of data 
    }); 

感謝您的幫助

+5

到底是什麼的問題/問題就在這裏? – 2013-05-01 16:09:25

+3

不客氣! – musefan 2013-05-01 16:09:43

+0

我想獲得數據的html代碼的變量結果: var result = .html(data); – Romain 2013-05-01 16:10:50

回答

2

數據變量信息IS實際您想要的HTML ...

$.get('ajax/test.html', function (data) { 
    var result = data; 
    alert(result); 
}); 

Here is a working example


然後,如果您想對HTML數據使用jquery,你必須將其轉換爲一個jQuery對象...

var htmlElement = $(result); 
//can now do htmlElement.find(... 

Here is an example that pulls the date from the BBC news website

+0

不用於把html變成'result'變量,我會說。 – Bergi 2013-05-01 16:13:56

+0

@Bergi:當時很難說出他想要的東西,我認爲他的代碼只是因爲某種原因被浪費了,並且他試圖將HTML放入元素中。 – musefan 2013-05-01 16:24:14

+0

感謝您的回答,但是,我仍然無法提取我想要的結果。 var boxes = new Array; $ .get('ajax/test.html',function(data){ var result = data.find('article')。each(function(key,value){boxes.obush(value); } (「#related_projects」)。gridalicious('append',boxes); }); } + 1爲您的答案 – Romain 2013-05-01 16:29:16