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 9027399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:44:15+00:00 2026-06-16T06:44:15+00:00

How could I pass PHP URL variables to AJAX so I can get the

  • 0

How could I pass PHP URL variables to AJAX so I can get the page content load in the same page ?? Here is an example of what I am trying to to do .. I am trying for example to get the “profile.php?id= to AJAX so that page content be be loaded .. However , I first started using a loop .. I dont know if that’s the right way to go about it ..

Below is the code

<div id="myDiv"><h2>Let AJAX change this text</h2></div>


<?php
require('../madscore/database/connect.php');
database_connect();
$query = "select * from Entertainers";
$result = $connection->query($query);
$row_count =$result->num_rows;

for($i = 1; $i <= $row_count; $i++)
  {
   $row = $result->fetch_assoc();
    //echo $i. "<br />";
   // echo $row['Name']."<br />";
   // echo $row['Profession']."<br />";
   // echo $row['Score']."<br />";

?>

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","profile.php?id="<?php echo $row['ID'] ?>, true");
xmlhttp.send();
}
</script>




<?php  echo "<a href='/profile.php?id=".$row['ID']."' onclick='loadXMLDoc()'><img src ='../".$row['Picture']."' width='100' height='100' /> </a>"; } ?>

</body>
</html>
  • 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-16T06:44:16+00:00Added an answer on June 16, 2026 at 6:44 am

    Change this —

    xmlhttp.open("GET","profile.php?id="<?php echo $row['ID'] ?>, true");
    

    To this —

    xmlhttp.open("GET","profile.php?id=<?php echo $row['ID'] ?>", true);
    

    EDIT as per comments –
    Try this-

    myid = <?php echo $row['ID'] ?>; 
    
    //myid = "<?php echo $row['ID'] ?>";  //Or this if its a string type 
    
    
    xmlhttp.open("GET","profile.php?id="+myid, true);
    

    After such a long chat —

    <?php  echo "<a href='/profile.php?id=".$row['ID']."' onclick='loadXMLDoc(".$row['ID'].")'><img src ='../".$row['Picture']."' width='100' height='100' /> </a>"; } ?>
    

    Pass $row['ID'] to your loadXMLDoc() method.

    Final Code —

    <div id="myDiv"><h2>Let AJAX change this text</h2></div>
    
    
    <?php
    require('../madscore/database/connect.php');
    database_connect();
    $query = "select * from Entertainers";
    $result = $connection->query($query);
    $row_count =$result->num_rows;
    
    for($i = 1; $i <= $row_count; $i++)
      {
       $row = $result->fetch_assoc();      
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function loadXMLDoc( myid )
    {
    var xmlhttp;
    var myloveid = id;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","profile.php?id="+myloveid, true");
    xmlhttp.send();
    }
    </script>
    
    
    
    
    <?php  echo "<a href='/profile.php?id=".$row['ID']."' onclick='loadXMLDoc(".$row['ID'].")'><img src ='../".$row['Picture']."' width='100' height='100' /> </a>"; } ?>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
I am curious how I could make a PHP script where you pass your
I'm wondering if someone could look over my code. I'm trying to pass a
I have this ajax code: return $.ajax({ type: POST, url: somefile.php, cache:false, data: {
someone here in SO told me that the hash (#) in the url could
I am trying to create an html form that uses AJAX to load database
I am trying to pass a variable to a php script using XMLHttpRequest and
I am trying to see how I can pass a dynamic input type through
I'm trying to pass an array to jquery's .ajax() function's data parameter. The first
I'm trying to create a Email to friend page using php. The objective of

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.