Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery not returning body.text
    primarykey
    data
    text
    <p>I have an ajax post sends a website address to php it retrieves it and then I want jquery to find certain elements within the site and retrieve the text in those elements. It works fine for a few elements like h1 h2 p a etc but not on all sites and I can't get body text and meta tags i.e. body.text returns nothing. Is it my ajax post or php causing the problem here?</p> <p>Here is my ajax post</p> <pre><code>var dataString = name; $.ajax({ type: "POST", url: "senddom.php", data: {"dataString" : dataString }, dataType: "json", success: function(response) { $('body').append("&lt;p&gt; contents of title:" + $(response).find("Title").text()+ "&lt;/p&gt;"); $('body').append("&lt;p&gt; contents of meta:" + $(response).find('Meta').text()+ "&lt;/p&gt;"); $('body').append("&lt;p&gt; contents of all: " + $(response).find('body').text() + "&lt;/p&gt;"); $(response).find('p').each(function() { $('body').append("&lt;p&gt; contents of p: " + $(this).text() + "&lt;/p&gt;"); }); </code></pre> <p>and my php which I have only started learning</p> <pre><code>&lt;?php $site= $_POST['dataString']; // get data function curl_get($site){ $useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$site); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); $data=curl_exec($ch); curl_close($ch); return $data; } function getdom($site){ $html = curl_get($site); // Create a new DOM Document $xml = new DOMDocument(); @$xml-&gt;loadHTML($html); echo json_encode($html); } echo getdom($site); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload