title: Load url into AJAX instead of on click and parse results?
body: <p>I had a webscraping technique all worked out in PHP until I found out that the platform I was developing it on (iOS via phone gap) didn't support PHP. I found a solution though, via JS.</p>
  
  <pre><code>$(document).ready(function(){
    var container = $('#target');
    $('.ajaxtrigger').click(function(){
      doAjax($(this).attr('href'));
      return false;
    });
    function doAjax(url){
      if(url.match('^http')){
        $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
                  "q=select%20*%20from%20html%20where%20url%3D%22"+
                  encodeURIComponent(url)+
                  "%22&amp;format=xml'&amp;callback=?",
          function(data){
            if(data.results[0]){
              var data = filterData(data.results[0]);
              container.html(data);
            } else {
              var errormsg = '&lt;p&gt;Error: could not load the page.&lt;/p&gt;';
              container.html(errormsg);
            }
          }
        );
      } else {
        $('#target').load(url);
      }
    }
    function filterData(data){
      data = data.replace(/&lt;?\/body[^&gt;]*&gt;/g,'');
      data = data.replace(/[\r|\n]+/g,'');
      data = data.replace(/&lt;--[\S\s]*?--&gt;/g,'');
      data = data.replace(/&lt;noscript[^&gt;]*&gt;[\S\s]*?&lt;\/noscript&gt;/g,'');
      data = data.replace(/&lt;script[^&gt;]*&gt;[\S\s]*?&lt;\/script&gt;/g,'');
      data = data.replace(/&lt;script.*\/&gt;/,'');
      return data;
    }
  });
  </code></pre>
  
  <p>The way the URL is loaded is by clicking a link and it get's the <code>href</code> of it and populates <code>url</code> (at least I think). I want the url to be static though, such as <code>http://website.com</code> and being pre populated. I tried replacing all <code>doAjax(url)</code> with <code>doAjax('http://website.com)</code> but that doesn't seem to work and I would like to know what I'm doing wrong.</p>
  
  <p>Another problem with the new JS script is that I want to be able to parse the results and only show the <code>table</code> element. In PHP, I did this using:</p>
  
  <pre><code>data =  $html-&gt;find('table');
  echo $data[1];
  </code></pre>
  
  <p>What would the equivalent be in javascript of that PHP function?</p>
  
  <p>On a side note, I was considering splitting this up into two posts, but I thought that would be too many posts for tonight :)</p>
  
  <p><strong>Edit: First problem was solved by @nnnnnn in the comments.</strong></p>