Jump to content
Sign in to follow this  
Rewillis

Using AJAX with a web server.

Recommended Posts

Attention: W3schools.com forum members:

     I just migrated my web files from a web hosting site to my personal computer system, which is currently configured as a dedicated web server.  The three files ( one ",jpg" image file, one ".json" JSON data file, and one AJAX file ( i.e., "AJAX_2.htm" ).  The code for the "AJAX_2.htm" and "mydata.json" files are as follows, respectively:

<html>
   <head>
      <meta content = "text/html; charset = ISO-8859-1" http-equiv = "content-type">
      <!--Adapted and edited by Russell E. Willis as of 12/28/18.-->
<style>
div.container {
    width: 100%;
    border: 1px solid gray;
}

article {
  @media only screen and (max-width: 35%) {
    body {
    margin-left: 35%;
    border-left: 1px solid gray;
    padding: 0em;
    overflow: hidden;
          }
    }
}

sup {
  vertical-align: super;
  font-size: x-small;
}

p1 {
   text-indent: 1px;
}

.text1 {
  margin: 15px;
}

.content-box {
  column-count: 2;
  -webkit-column-rule: 1px double purple;
  -moz-column-rule: 1px double purple;
  column-rule: 1px double purple;
  margin: 15px;
}
</style>  
<div class="container">
		
      <script type = "application/javascript">
         function loadJSON() {
            var data_file = "mydata.json";
            var http_request = new XMLHttpRequest();
            try{
               // Opera 8.0+, Firefox, Chrome, Safari
               http_request = new XMLHttpRequest();
            }catch (e) {
               // Internet Explorer Browsers
               try{
                  http_request = new ActiveXObject("Msxml2.XMLHTTP");
					
               }catch (e) {
				
                  try{
                     http_request = new ActiveXObject("Microsoft.XMLHTTP");
                  }catch (e) {
                     // Something went wrong
                     alert("Your browser broke!");
                     return false;
                  }
					
               }
            }
			
            http_request.onreadystatechange = function() {
			
               if (http_request.readyState == 4  ) {
                  // Javascript function JSON.parse to parse JSON data
                  var jsonObj = JSON.parse(http_request.responseText);

                  // jsonObj variable now contains the data structure and can
                  // be accessed as jsonObj.name and jsonObj.country.
            
                  document.getElementById("Book").innerHTML = jsonObj.book;
                  document.getElementById("Chapter").innerHTML = jsonObj.chapter;
                  document.getElementById("Verse").innerHTML = jsonObj.verse;
               }
            }
			
            http_request.open("GET", data_file, true);
            http_request.send();
         }
		
      </script>
	
      <title>The Holy Bible.</title>
   </head>
	
   <body>
       
      <h3>&#160&#160&#160Please click the "Bible Verse" button below to read a Bible verse ( <i>ESV</i> ),
      and read the article below:</h3>
      
      <center><table class = "src">
         <tr><th><ins>Book</ins></th><th><ins>Chapter</ins></th><th><ins>Verse</ins></th></tr>
         <tr><td><div id = "Book">Matthew</div></td>
         <td><div id = "Chapter">1</div></td>
         <td><div id = "Verse">1</div></td></tr>
      </table></center>

      <center><div class = "central">
         <button type = "button" onclick = "loadJSON()">Bible Verse</button>
      </div></center>
<br>


<center><ins>T<font size="2" color="black">HE</font> H<font size="2" color="black">OLY</font>
B<font size="2" color="black">IBLE</font>: E<font size="2" color="black">NGLISH</font>
S<font size="2" color="black">TANDARD</font> V<font size="2" color="black">ERSION.</font></ins></center><br>		

<center><img src="Holy_Bible_ESV_6_crop (635x640).jpg" height="300" width="300"></center><br> 
<center><ins><font size="3" color="black">The Titles Of Jesus.</font><ins></center>
<article>
<p align="justify" class="content-box">&#160&#160&#160In Isaiah 9:6, it is written,
"&#8202<sup><b>6</b></sup>&#8202<sup><i>u</i></sup>&#8202For to us a child is born,
to us <sup><i>v</i></sup>&#8202a son is given; <sup><i>w</i></sup>&#8202and the
government shall be <sup><i>x</i></sup>&#8202upon<sup><i>1</i></sup> his shoulder,
and his name shall be called<sup><i>2</i></sup> Wonderful <sup><i>y</i></sup>&#8202Counselor,
<sup><i>z</i></sup>&#8202Mighty God, <sup><i>a</i></sup>&#8202Everlasting <sup><i>b</i></sup>&#8202Father,
Prince of <sup><i>c</i></sup>&#8202Peace.&#8202"  Jesus ( see also Luke 2:11, for
example ) has the same titles as God, through the concept of the Godhead.<sup><i>1</i></sup>  This
would explain the phrase "&#8202<sup><i>a</i></sup>&#8202Everlasting <sup><i>b</i></sup>&#8202Father,&#8202"
for example ( as we read in verse six ).  Furthermore, God said of His Son in Hebrews
1:8 ( please begin reading at verse one to get the immediate context ), "&#8202<sup><b>8</b></sup>&#8202But
of the Son he says, <sup><i>r</i></sup>&#8202'&#8202Your throne, O God, is forever
and ever, the scepter of uprightness is the scepter or your kingdom.&#8202'"  In
the verse three implied in this latter passage of Scripture, we observe that Jesus
( see also Matthew 1:16; 16:13-20 ( especially verse 16, for example ), for example
) is the exact imprint of the nature of God.  This observation allows us to correctly
state that Jesus is the Everlasting Father, in the sense that He is the exact imprint
of God's nature. The concept of the Godhead is clearly stated in 1 John 5:6, 7 (
<i>KJV</i>; with center-column references ), namely: "6&#8202This is he that came <sup><i>a</i></sup>by water and blood, <i>even</i>
Jesus Christ; not by water only, but by water and blood.  <sup><i>b</i></sup>And
it is the Spirit that beareth witness, because the Spirit is truth.  7&#8202For
there are three that bear <sup>1</sup>record in heaven, the Father, <sup><i>a</i></sup>the
Word, and the Holy Ghost: <sup><i>b</i></sup>and these three are one.&#8202"  The
Godhead is defined as follows: one God&#8202&#151&#8202three Persons.  May we, as
children of God ( see Galatians 3:26, 27, for example ), imitate the Lamb of God
( see John 1:29; 1 Corinthians 11:1, for example ). Jesus is "&#8202<sup><i>l</i></sup>&#8202the
bright morning star&#8202" ( see Revelation 22:16 ). &#128366</p><br>


&#160&#160&#160&#160&#95&#95&#95&#95&#95&#95&#95&#95<br>
<p1 class="text1"><font size="2" color="black">1. <i>HOLMAN <b>BIBLE</b> DICTIONARY,</i>
<b>GENERAL EDITOR</b>: BUTLER, TRENT C., PH.D., HOLMAN BIBLE PUBLISHERS, &#169 Copyright
1991 Holman Bible Publishers, pp. 252, 1373, for example.</font></p1><br>
<p1 class="text1"><font size="2" color="black">NOTE: Be careful not to confuse this
footnote with the one indicated in the first verse six, or the equivalent translation
indicated in the second verse seven&#8202&#151&#8202both verses of which are quoted
above.</font></p1><br>
<br>
</article>
</div> 
</body>
		
</html>
{"book": "Matthew", "chapter": "1", "verse": "<b>1</b>.  <sup>a</sup>The
book of the genealogy of Jesus Christ, <sup>b</sup>the son of David,
<sup>c</sup>the son of Abraham."}

I also added the following line of code to my web server configuration file:

# Edited as of Saturday, January 19, 2019.
    AddType application/json .json
# End edited as of Saturday, January 19, 2019.

After making the above-given edit to my web server configuration file, when I click on the "Bible Verse" button, I get no response.  I posted most of the above-given code recently, and solved that problem by uploading my above-mentioned web files to the web hosting site.  However, I am not sure what more to do since I have migrated those web files to my personal computer and served them up from there.  What am I doing wrong or overlooking?  Thank you ( see Colossians 3:15, for example ) for your help and your patience.  Keep in touch. 😊

Sincerely in Christ,

Russell E. Willis

P.S. - Please read Proverbs 23:23.

Edited by Rewillis

Share this post


Link to post
Share on other sites

Attention: W3schools.com forum members:

     After making the following edits to my web server configuration file, and my "mydata.json" JSON data file, respectively, my interactive web page is now working:

ScriptAlias "/cgi-bin/" "c:/Apache24/Apache24/cgi-bin/"

The quotation marks were missing around the "/cgi-bin/" portion of the above-given line of code ( not the path name ).  Then, we have:

AddHandler cgi-script .cgi .pl

Then, we have:

Options +ExecCGI

The above-given line of code was added in one of my "<VirtualHost></VirtualHost> containers.  And, finally, we have:

{"book": "Matthew", "chapter": "1", "verse": "<b>1</b>.  <sup>a</sup>The book of the genealogy of Jesus Christ, <sup>b</sup>the son of David, <sup>c</sup>the son of Abraham."}

The above-given line of code, in my "mydata.json" JSON data file, had to be changed from three lines to one line.  Thank you ( see Colossians 3:15, for example ) to all those on this forum who at least viewed my previous posting.  Keep in touch. ☺️

Sincerely in Christ,

Russell E. Willis

P.S. - Please read Proverbs 23:23.

Edited by Rewillis

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...