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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:03:15+00:00 2026-05-30T10:03:15+00:00

I have a .php file on the server. I want it to send values

  • 0

I have a .php file on the server. I want it to send values 1 or 2 depending on the locks that it acquired. However i am unable to use the server response in Javascripts. I have tried using innerHTML but i don’t know how to use its value. I am totally new to AJAX so pls forgive any stupid mistakes that i might’ve made.

.php file

 <?php
 $fp1=fopen("a1.jpg","r");
 $fp2=fopen("a2.jpg","r");
 if(flock($fp1,LOCK_EX))
 {
    echo "a1 locked";
    $ch=1;
 }
 else
 {
    flock($fp2,LOCK_EX);
    echo "a2 locked";
    $ch=2;
 }
 $response=$ch;
 echo $ch;
 echo $response;
 ?>

.html file

<html>
<head>
 <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Smart Surveillance Camera</title>
<script language="Javascript">

function loadXMLDoc()
{
    var xmlhttp;
    xmlhttp=new XMLHttpRequest();
    //document.write ("request created");
    xmlhttp.onreadystatechange=reload()
    {
            if(xmlhttp.readyState==4 && xmlhttp.status==200)
                    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    xmlhttp.open("GET","lock.php",true);
    xmlhttp.send();
    //document.write (serverResponse);
    loadXMLDoc();
}

function reload()
{
    document.write ();
    if(myDiv==1)
            document.campicture.src="a1.jpg";
    else
            document.campicture.src="a2.jpg";

}
</script>
</head>

<body bgcolor="white" onLoad="loadXMLDoc()">
<div id="myDiv">
<center>
<font size==-1>
<h1>SMART SURVEILLANCE CAMERA PAGE</h1>
<img name="campicture" src="founders.jpg" border=1 width=320 height=240 alt="AYS         founder's IMAGE"><br />
</font>
</center>
</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-05-30T10:03:16+00:00Added an answer on May 30, 2026 at 10:03 am

    The code xmlhttp.onreadystatechange=reload() isn’t going to do what you want it to. That’s neither defining nor assigning a function to the onreadystatechange callback. To define the callback, your code should look like either of the following:

    xmlhttp.onreadystatechange = reload;
    
    //later
    function reload() {
        //the actions to do on response
    }    
    

    or

    xmlhttp.onreadystatechange = function() {
        // the actions to do on response
    }
    

    There won’t be much difference for your current use of it. Whichever you choose to use, inside is where you should have your if(xmlhttp.readyState==4 && xmlhttp.status==200) code.

    Then it comes to using the value you’ve received. It looks like you’re setting the value into myDiv and then attempting to use the value later (although myDiv == 1 won’t work anyway). However, you don’t need to do that. In your readystatechange function, you can just use the value directly:

    if (xmlhttp.responseText == "1")
        document.campicture.src="a1.jpg";
    else
        document.campicture.src="a2.jpg";
    

    Remember, that part goes inside the function (anonymous or otherwise) that gets bound to onreadystatechange.

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

Sidebar

Related Questions

Okay, So I have a PHP file that uploads a image to my server.
I have a PHP file that contains a lot of if and else statements
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
i am trying to send email from php i have one php file with
I have a PHP application that makes extensive use of Javascript on the client
I have a php script on a local server that creates and manages an
I have a PHP file. Based on the PHP the server generates a output
I have a PHP script that produces a .CSV export file from a MySQL
I have: $page_file_temp = $_SERVER[PHP_SELF]; which will output: /templates/somename/index.php I want to extract from
i have a php file launching my exe. the exe does cout and the

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.