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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:41:29+00:00 2026-05-18T10:41:29+00:00

I have created a very basic page that retrieves all contacts from my contact

  • 0

I have created a very basic page that retrieves all contacts from my contact MySQL table using AJAX:

index.php

html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>mycontacts.</title>
    <script type="text/javascript" src="JavaScripts/PrintContacts.js"></script>
  </head>

  <body>
    <div class="main-wrapper">
      <div id="main-content">

        <script type="text/javascript">
          printContacts();
        </script>

        <div id="contacts">
        </div>

      </div>
    </div>
  </body>
</html>

PrintContacts.js

var xmlHttp;

function printContacts() {
  xmlHttp = new XMLHttpRequest();
  var url = "PHP/getAllContacts.php";

  // Workaround for page caching
  url = url + "&sid=" + Math.round(Math.random() * 1000000000);
  // Commenting the line above removes my issue but I do need this for caching!!!

  // Manage XmlHttpObject state change
  xmlHttp.onreadystatechange = stateChanged;

  xmlHttp.open("POST", url, true);
  xmlHttp.send(null);
}

function stateChanged() {
  // Check if the XmlHttp request is complete
  if (xmlHttp.readyState == 4) {
    // Set the XmlHttp response in the div contacts
    document.getElementById("contacts").innerHTML = xmlHttp.responseText;
  }   
}

getAllContacts.php

<?php
$dbconnection = mysql_connect("localhost", "root", "");
mysql_select_db("mycontacts", $dbconnection);

$command = "SELECT * FROM contact";
$result = mysql_query($command);

echo "<table border='1'>";

// Table headers
echo "<tr><th>Name</th></tr>";

// Print all contacts
while($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['DisplayName'] . "</td>";
  echo "</tr>";
}

echo "</table>";

mysql_close($dbconnection);
?>

Opening the getAllContacts.php directly returns the appropriate table with the data, however, opening index.php, results in an error:

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.

Error 404

localhost
12/08/2010 2:47:27 PM
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

I found out that adding &SID= is the root of the issue. This is happening in the PrintContacts.js file. Removing that loads the page appropriately. But I DO need that in order to workaround the caching. Do you know how to resolve this?

Thanks for all the help.

Solution

When adding SID to the url (for caching purposes), it should be appended with “?sid=” instead of “&sid=”. Changing this resolves the issue; it was a typo after all!

function printContacts() {
  xmlHttp = new XMLHttpRequest();
  var url = "PHP/getAllContacts.php";

  // Workaround for page caching
  url = url + "&sid=" + Math.round(Math.random() * 1000000000);
  ...
  • 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-05-18T10:41:30+00:00Added an answer on May 18, 2026 at 10:41 am

    When using AJAX, the url should be linked based on the browser’s current location, not the location of the javascript file.

    Change the url in printContacts() to just “PHP/getAllContacts.php”.

    EDIT: Ok… I figured it out! In the PrintContacts.js, you need to change this line

    url = url + "&sid=" + Math.round(Math.random() * 1000000000);
    

    to this…

    url = url + "?sid=" + Math.round(Math.random() * 1000000000);
    

    Note the question mark in there. Having the & made it look for a file named getAllContacts.php&192837, not a file named getAllContacts.php.

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

Sidebar

Related Questions

I have a very basic web page that uses flot to create a canvas
I currently have a very simple intranet that we are using for some basic
I have created a very basic service operation that needs to write content to
I have created a very simple sharepoint timer job. All i want it to
I am using SQL Server 2008 Enterprise. I have created a very simple test
I have created a php person class and a very basic form. The form
I have a HTML page that I have created that essentially consists of: <div>
I have a very basic sign up and log in setup running and all
I realize that this is probably a very basic question, but I have spent
I finally have jQuery AJAX down pretty well and have my website all created,

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.