2022-11-16

Nov 16 In-Class Exercise Thread .

Please post your solution to the Nov 16 In-Class Exercise to this thread.

Best,

Chris

Please post your solution to the Nov 16 In-Class Exercise to this thread. Best, Chris

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html lang="en-US">

   <head>
       <title>In Class Exercise 11/16</title>
       <meta charset="utf-8"/>
   </head>
   <body>
       <script>
           function findTotalResults(obj)
           {
               alert(obj.totalResults);
           }
       </script>
       <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script>
   </body>

</html>

<!DOCTYPE html> <html lang="en-US"> <head> <title>In Class Exercise 11/16</title> <meta charset="utf-8"/> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script> </body> </html>

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html> <head> <meta name="charset" content="utf-8"/> <title>11/16 Excercise</title> </head> <body> <script> function findTotalResults(json){ alert(JSON.parse(json).totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html>

<!DOCTYPE html> <html> <head> <meta name="charset" content="utf-8"/> <title>11/16 Excercise</title> </head> <body> <script> function findTotalResults(json){ alert(JSON.parse(json).totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html>

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html> <head> <title>JSONP</title> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults) } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults" /> </body> </html>

<nowiki><!DOCTYPE html> <html> <head> <title>JSONP</title> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults) } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults" /> </body> </html> </nowiki>

-- Nov 16 In-Class Exercise Thread

<!doctype html> <html> <head> <title>in class exercise</title> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html>

<nowiki><!doctype html> <html> <head> <title>in class exercise</title> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html></nowiki>

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html lang="en-UK"> <head> <title>In Class Excercize</title> <meta name="charset" content="utf-8"/> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html>

<nowiki> <!DOCTYPE html> <html lang="en-UK"> <head> <title>In Class Excercize</title> <meta name="charset" content="utf-8"/> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"/> </body> </html> </nowiki>

-- Nov 16 In-Class Exercise Thread

One issue with this exercise as stated is to get the alert to fire correctly. I think most browsers get hung up on the fact the document isn't fully written when we try to call the alert. The code below though does work:

<!DOCTYPE html>
<html lang="en-US">
   <head>
       <title>In Class Excercise</title>
       <meta name="charset" content="utf-8"/>
   </head>
   <body onload="alert(document.getElementById('foo').innerHTML)">
       <div id="foo" style="display:none;">
       </div>
       <script>
       function findTotalResults(obj)
       {
           document.getElementById("foo").innerHTML =
               obj.totalResults;
       }
       </script>
       <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults">
       </script>
   </body>
</html>

To get a really awesome solution embed the creation of the onload event handler into findTotalResults.

(Edited: 2022-11-16)
One issue with this exercise as stated is to get the alert to fire correctly. I think most browsers get hung up on the fact the document isn't fully written when we try to call the alert. The code below though does work: <!DOCTYPE html> <html lang="en-US"> <head> <title>In Class Excercise</title> <meta name="charset" content="utf-8"/> </head> <body onload="alert(document.getElementById('foo').innerHTML)"> <div id="foo" style="display:none;"> </div> <script> function findTotalResults(obj) { document.getElementById("foo").innerHTML = obj.totalResults; } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"> </script> </body> </html> To get a really awesome solution embed the creation of the onload event handler into findTotalResults.
2022-11-17

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html>

   <head>
       <title>11/16</title>
   </head>
   <body>
       <script>
           function findTotalResults(obj){
               alert(obj.totalResults);
           }
           </script>
       <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script>
   </body> 

</html>

<!DOCTYPE html> <html> <head> <title>11/16</title> </head> <body> <script> function findTotalResults(obj){ alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script> </body> </html>

-- Nov 16 In-Class Exercise Thread

<head>

       <title>In Class Exercise 11/16</title>

</head>

   <body>
       <script>
           function findTotalResults(obj)
           {
               alert(obj.totalResults);
           }
       </script>
       <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script>
   </body>

</html>

<head> <title>In Class Exercise 11/16</title> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script> </body> </html>

-- Nov 16 In-Class Exercise Thread

<!DOCTYPE html> <html lang="en-US">

   <head>
       <title>In Class Exercise 11/16</title>
       <meta charset="utf-8"/>
   </head>
   <body>
       <script>
           function findTotalResults(obj)
           {
               alert(obj.totalResults);
           }
       </script>
       <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script>
   </body>

</html>

<!DOCTYPE html> <html lang="en-US"> <head> <title>In Class Exercise 11/16</title> <meta charset="utf-8"/> </head> <body> <script> function findTotalResults(obj) { alert(obj.totalResults); } </script> <script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults"></script> </body> </html>
[ Next ]
X