Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:44:32+00:00 2026-06-17T17:44:32+00:00

I have spent ages at this and dont understand why it is not working.

  • 0

I have spent ages at this and dont understand why it is not working. I am using ajax to send a post to php curl which brings a url in it then goes back to ajax. When I send an alert all the html of that page is displayed in the alert. Now I want to use jquery to find each element i.e. body, h1, title and output the contents but when I do this it doesnt work for the body or title. Why is that?

Here is my jquery

        $.ajax({
      type: "POST",
      url: "senddom.php",
      data: {"dataString" : dataString },
      success: function(response) {   
  $('body').append("<p> contents of title:" + $(this).find('title').html() + "</p>");       
  $('body').append("<p> contents of all: " + $(this).find('body').html() + "</p>");

 $(response).find('h1').each(function() {
  $('body').append("<p> contents of H1: " + $(this).text() + "</p>");
});

this is my php

<?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);
    $xml = new DOMDocument();
    @$xml->loadHTML($html);
    echo($html);


}

echo getdom($site);

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:44:33+00:00Added an answer on June 17, 2026 at 5:44 pm

    inside your success block: $(this) -> $(response)

    Follow Up: Full text HTML vs Fragments

    While this may seem to take care of the immediate problem, it is dependent on whether or not your response is the full body HTML.

    In this case, it seems as though response is the full text HTML.

    The jQuery parseHTML method does not deal with full text HTML, and unfortunately response won’t be parsed properly. Fore more info see: https://github.com/jquery/jquery/blob/master/src/core.js

    In the case where you are looking to parse full text HTML, one approach would be to use the DOMParser API. It is worth noting that the support for parsing "text/html" is currently lacking; only available in Firefox. An alternative is document.implementation which has support in all but IE<9.

    That said, an example in the case where you want to use DOMParser —

    parser = new DOMParser();
    doc = parser.parseFromString(response, "text/html");
    $response = $(doc)
    $response.find('title').text()
    

    An example in the where you want to use documentation.implementation —

    var doc = document.implementation.createHTMLDocument("");
    var doc_el = doc.documentElement;
    doc_el.innerHTML = response;
    $response = $(doc_el); // 
    $response.find('title').text()
    

    For more information, I’ll defer to a nice jQuery plugin (that deals with the x-browser support) that I found on github: jquery.parsehtml.js.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent last 3 days until I got gps working on android using
I have spent many hours working on this program that is supposed to play
Having just spent ages debugging this, I'm keen to understand what exactly is going
I have spent over a week trying to get this working and I am
Sorry I am sure this is easy but I have spent ages trying to
Have spent an hour trying to solve this - but to no avail. I'm
I have spent hours in this problem and my fellows couldn't help me out.
I have spent all Friday and Saturday on this and I am running out
I have spent some time now to solve a problem for which i have
I have spent about half a day searching for an answer to this question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.