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

  • Home
  • SEARCH
  • 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 8578091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:18:29+00:00 2026-06-11T20:18:29+00:00

I recently switched from XML to PHP for use with my simple AJAX program.

  • 0

I recently switched from XML to PHP for use with my simple AJAX program. However, I can’t figure out how to find and pull element’s data with .each like I did with the XML file format.

The HTML outputted is correct: When people type in a search, they receive a php page generated from a MySQL database.

What I want to happen is to use .each to grab a “div.product”, then look through the elements contained within that div and use their data to append my page with much more elements and styling.

function htmlParser() {
    var search_name_field = $("input.search").val();
    $.ajax({
        type: "POST",
        url: "load_data.php?product=" + search_name_field,
        cache: false,
        dataType: "html",
        success: function(html){
            alert(html);    // This shows php response perfectly
            $(html).find("div.product").each(function(){    
                alert("success!"); // Doesn't appear
                var productcode = $(this + "div.product_detail").data("code");
                alert(productcode);
                $("#output").empty();
                $("#output").append("Product Code: " + productcode + "<br>"); 
            });
        }
    })
}

Here is the the first two div.product from the alert generated by alert(html)

<span class="con_status">Connected successfully</span>
<div class="product">
    <div class="product_detail" data-code="HW100"></div>
    <div class="product_detail" data-name="Loaded Hardware 1&quot;"></div>
    <div class="product_detail" data-price="7"></div>
    <div class="product_detail" data-hideproduct=""></div>
    <div class="product_detail" data-stockstatus="13"></div>
    <div class="product_detail" data-productdescriptionshort=""></div>
    <div class="product_detail" data-producturl=""></div>
    <div class="product_detail" data-photourl=""></div>
</div>
<div class="product">
    <div class="product_detail" data-code="HW125"></div>
    <div class="product_detail" data-name="Loaded Hardware 1.25&quot;"></div>
    <div class="product_detail" data-price="7"></div>
    <div class="product_detail" data-hideproduct=""></div>
    <div class="product_detail" data-stockstatus="13"></div>
    <div class="product_detail" data-productdescriptionshort=""></div>
    <div class="product_detail" data-producturl=""></div>
    <div class="product_detail" data-photourl=""></div>
</div>

Edit: A problem with my ajax is it only can load the first data element. I fixed this by moving all the data into one single element. I could have also renamed all the elements to different classes. I don’t know which is better, but I am using the formal.

<div class="result">
    <div class="product"><div class="product_detail"
    data-code="LCSDC"
    data-name="Loaded Longboards - Dervish COMPLETE" data-price="240"
    data-hideproduct="Y"
    data-stockstatus="0"
    data-productdescriptionshort="Dervish longboard deck from Loaded Carving Systems. With a lower center of gravity and a torsionally stiff design- the Dervishes are built to hold an edge and maximize energy return. A drop-thru carver designed to work with most reverse kingpin 180mm Trucks &amp; 70mm+ wheels. Small nose and tail for manual &amp; shovits."
    data-producturl=""
    data-photourl="">
    </div></div>
</div>
  • 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-11T20:18:30+00:00Added an answer on June 11, 2026 at 8:18 pm

    There are two problems in your JavaScript code.

    As I recall, there should be only one root element when you do something like $(html).

    One quick solution to that is to add this line

    html = "<div>" + html + "</div>";
    $(html).find("div.product").each(function(){
    

    Or you can change your PHP to output the result wrapped with:

    <div class="result">...</div>
    

    The success alert will then work.

    The other problem is about this line

    $(this + "div.product_detail")
    

    It should be something like

    $(this).find("div.product_detail")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently switched from PHP to Web2Py and was wondering if Web2Py has a
I recently switched over from SVN to Hg. I used to use TortoiseSVN, and
We recently switched from Ant to Buildr for building our projects. We use Ivy
Recently switched from MacVim to standard vim so I can force myself to move
I recently switched from MySQL to PostgreSQL. I have one problem left however. Previously,
I recently switched from Vim to MacVim because it has Ruby support, however, the
I've recently switched from a Windows XP machine to Windows 7. I use Subversion
I recently switched from Eclipse to Intellij. Now I'm trying to use the andengine
I just recently switched from bash to zsh, however I miss my Alt +
I recently switched from a Java based project to a C#/.net project. I previously

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.