Question

Please advise what is being doing wrong. Requirement. See if you can modify the code of...

Please advise what is being doing wrong.

Requirement.

See if you can modify the code of Listings 17.1 and 17.3 to present a message to the user while waiting for an Ajax request to complete.

//Code

<!DOCTYPE html>

<html>

<head>

<title>Keywords Grabber</title>

<script src="myAjaxLib.js"></script>

<script>

function display(content) {

document.getElementById("displaydiv").innerHTML = content;

</script>

<script>

function getXMLHttpRequest() {

try {

try {

return new ActiveXObject("Microsoft.XMLHTTP");

}

catch(e) {

return new ActiveXObject("Msxml2.XMLHTTP");

}

}

catch(e) {

return new XMLHttpRequest();

}

}

function doAjax(url, query, callback, reqtype, getxml) {

var myreq = getXMLHttpRequest();

myreq.onreadystatechange = function() {

if(myreq.readyState == 4) {

if(myreq.status == 200) {

var item = myreq.responseText;

if(getxml == 1) item = myreq.responseXML;

eval(callback + '(item)');

}

}

}

if(reqtype.toUpperCase() == "POST") {

requestPOST(url, query, myreq);

} else {

requestGET(url, query, myreq);

}

}

function requestGET(url, query, req) {

var myRandom = parseInt(Math.random()*99999999);

if(query == '') {

var callUrl = url + '?rand=' + myRandom;

} else {

var callUrl = url + '?' + query + '&rand=' + myRandom;

}

req.open("GET", callUrl, true);

req.send(null);

}

function requestPOST(url, query, req) {

req.open("POST", url, true);

req.setRequestHeader('Content-Type', 'application/x-www-form-

urlencoded');

req.send(query);

} }

window.onload = function(){

document.getElementById("btn1").onclick = function(){

var url = document.getElementById("txt1").value;

doAjax("metatags.php", "url=" + url, "display", "post", 0);

}

}

</script>

</head>

<body>

http://<input type="text" id="txt1" value="" />

<input type="button" id="btn1" value="Get Keywords" />

<h3>Keywords Received:</h3>

<div id="displaydiv"></div>

</body>

</html>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Note: Here I have modified little and giving the new code.

code:

<!DOCTYPE html>

<html>

<head>

<title>Keywords Grabber</title>

<script src="myAjaxLib.js"></script>

<script>

function display(content) {

document.getElementById("displaydiv").innerHTML = content;
}

</script>

<script>

function getXMLHttpRequest() {

try {

try {

return new ActiveXObject("Microsoft.XMLHTTP");

}

catch(e) {

return new ActiveXObject("Msxml2.XMLHTTP");

}

}

catch(e) {

return new XMLHttpRequest();

}

}

function doAjax(url, query, callback, reqtype, getxml) {

var myreq = getXMLHttpRequest();

myreq.onreadystatechange = function() {

if(myreq.readyState == 4) {

if(myreq.status == 200) {

var item = myreq.responseText;

if(getxml == 1) item = myreq.responseXML;

eval(callback + '(item)');

}

}

}

if(reqtype.toUpperCase() == "POST") {

requestPOST(url, query, myreq);

} else {

requestGET(url, query, myreq);

}

}

function requestGET(url, query, req) {

var myRandom = parseInt(Math.random()*99999999);

if(query == '') {

var callUrl = url + '?rand=' + myRandom;

} else {

var callUrl = url + '?' + query + '&rand=' + myRandom;

}

req.open("GET", callUrl, true);

req.send(null);

}

function requestPOST(url, query, req) {

req.open("POST", url, true);

req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

req.send(query);

}

window.onload = function(){

document.getElementById("btn1").onclick = function(){

var url = document.getElementById("txt1").value;

doAjax("metatags.php", "url=" + url, "display", "post", 0);

}

}

</script>

</head>

<body>

http://<input type="text" id="txt1" value="" />

<input type="button" id="btn1" value="Get Keywords" />

<h3>Keywords Received:</h3>

<div id="displaydiv"></div>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
Please advise what is being doing wrong. Requirement. See if you can modify the code of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • I am trying to create a slide show using JavaScript. This is what I have so...

    I am trying to create a slide show using JavaScript. This is what I have so far: HTML: <!DOCTYPE html> <html lang="en"> <head>    <meta charset="utf-8"> <title>Slide Show</title> <link rel="stylesheet" href="main.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="slide_show.js"></script> </head> <body> <section> <h1>Fishing Slide Show</h1> <ul id="image_list"> <li><a href="images/casting1.jpg" title="Casting on the Upper Kings"></a></li> <li><a href="images/casting2.jpg" title="Casting on the Lower Kings"></a></li> <li><a href="images/catchrelease.jpg" title="Catch and Release on the Big Horn"></a></li> <li><a href="images/fish.jpg" title="Catching on the South Fork"></a></li> <li><a href="images/lures.jpg" title="The Lures for Catching"></a></li> </ul>...

  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Da...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hands-on Project 4-3</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 4-3 </h1> </header> <article> <div id="results"> <p id="resultsExpl"></p> <ul> <li id="item1"></li> <li id="item2"></li> <li id="item3"></li> <li id="item4"></li> <li id="item5"></li> </ul> </div> <form> <fieldset> <label for="placeBox" id="placeLabel"> Type the name of a place, then click Submit: </label> <input type="text" id="placeBox"...

  • This question relates to Javascript. Could you please show me why my code is not working?...

    This question relates to Javascript. Could you please show me why my code is not working? I want to create 2 text boxes and have the user enter something into both of them. If the text entered into both boxes is identical the a green message is made visible. If the boxes are different a red message is made visable. Please keep it simple because I am new to javascript. <html> <head>               <title></title>        <script>...

  • <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">      &n

    <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">         <!--div class-->       <div class="formvalidation">       <label>Your first Name</label>        <span id="showname"></span>        <!--label for firstname-->       <input type="text" name="firstname" class="formsignup"  id ="firstn" placeholder="Enter your Name">      <br><br>           <!--lastname-->       <label>Your last Name</label> <span id="showlname"></span>       <input type="text" name="lastname" class="formsignup" id="lastn" placeholder="Enter your last Name">       <br><br>        <!--email-->         <label>Your Email</label>          <span id="showemail"></span>         <input type="email" name="emailid" class="formsignup" size="45" id="emailn" placeholder="Enter your Email">        <br><br> <input type="submit" value="send">     </div>           </form> <script>      function checkvalidation(){     var name = document.forms["validationForm"]["firstname"].value;     var lname...

  • Modify this code to store the form elements as variables and display them on the page...

    Modify this code to store the form elements as variables and display them on the page in an HTML table. <!DOCTYPE html> <html> <head> <script> function getValues() {     var result = ""; result += "First Name: " + document.forms["myForm"]["fname"].value + "<br>"; result += "Last Name: " + document.forms["myForm"]["lname"].value + "<br>"; result += "Address: " + document.forms["myForm"]["address"].value + "<br>"; result += "City: " + document.forms["myForm"]["city"].value + "<br>"; result += "State: " + document.forms["myForm"]["state"].value + "<br>"; document.getElementById("output").innerHTML = result; } </script>...

  • Modify the following file, so that: If the user input for the age input box is...

    Modify the following file, so that: If the user input for the age input box is empty, please send the user a warning message: “Age field cannot be empty” and return to the form web page to allow the user to re-input the age; If the user input for the age input box is incorrect (e. g. less than 1), please also send the user a warning message: “Your age input is not correct!” and return to the form web...

  • Trying to understand java script.. The code provided prints out a game board of cells that...

    Trying to understand java script.. The code provided prints out a game board of cells that are 10 x 10.   I currnetly have it printed out so that it will print out pink squares. how can i create a click even on any of the pink squares that when they are clicked it will turn the square black...   then any square that is black when it is clicked it will change back to the color pink html/js code and css...

  • I can't figure this one out at all. Any help would be appreciated. Here's the question:...

    I can't figure this one out at all. Any help would be appreciated. Here's the question: You will need to complete the functions to Toggle the Fries and Drinks sections by adding or removing the 'hide' CSS class I created. I have already created the function to Toggle Burgers and you can use that as an example to build out the full functionality. I have also made created the function to reset the form. Finally, to calculate the total, you...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT