michelepizzi

Ricevere le informazioni da un sito HTML

Jan 5th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery.ajax({
  2.     url:'string', // URL
  3.     type:'get',
  4.     dataType:'html',
  5.     success:function(data) {
  6.         var _html= jQuery(data); // pagina generata
  7.  
  8.         // ricavare il testo da una classe
  9.         var string_a = $('.CLASS', _html).text();
  10.  
  11.         // ricavare l'html da un ID
  12.         var string_b = $('#ID', _html).html();
  13.  
  14.         // visualizzare tutti i contenitori DIV
  15.         $('div', _html).each(function() {
  16.             console.log($( this ));
  17.         });
  18.  
  19.         // ricavare il testo dal contenitore p con una determinata classe
  20.         var string_c = $('p', _html).find('.CLASS').text();
  21.     }
  22. });
Advertisement
Add Comment
Please, Sign In to add comment