On Dec 14, 2012, at 5:21 AM, tab1ta wrote:
> Hello. i'm just approaching Javascript through an old book.
> do you see anything wrong in the funcions listed below?
>
>
> Link Test
>
> http://joy.indivia.net";>Click me />
>
> onError = errorHandler
> url = mylink.href
> document.write('The URL is ' + url)
>
> function errorHandler(message, url, line)
> {
> out = "Sorry, an error was encountered.\n\n";
> out += "Error: " + message + "\n";
> out += "URL: " +url + "\n";
> out += "Line: " +n line + "\n\n";
> out += "Click OK to continue.\n\n";
> alert(out);
> return true;
> }
>
>
> Your browser doesn't support or has disabled
> Javascript
>
>
>
>
> And in those other functions?
>
> Ajax XML Example
> Loading a web page into a div
> This sentence will be replaced
>
> // params = "url=oreilly.com"
> nocache = "&nocache=" + Math.random() * 100
> url = "rss.mews.yahoo.com/rss/topstories"
TYPO?? mews == news?
> request = new ajaxRequest()
> request.open("GET", "xmlget.php?url=" + url + nocache, true)
> //request.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded")
> //request.setRequestHeader("Content-length", params.length)
> //request.setRequestHeader("Connection", "close")
> out ="";
>
> request.onreadystatechange = function()
> {
> if(this.readyState == 4)
> {
> if (this.status == 200)
> {
> if (this.responseText != null)
> {
> titles = this.responseXML.getElementsByTagName('title')
> for (j = 0 ; j < titles.length ; ++j)
> {
> out += titles[j].childNodes[0].nodeValue + '
'
> }
> document.getElementById('info').innerHTML = out
> }
> else alert("Ajax error: No data received")
> }
> else alert("Ajax error: " this.statusText)
> }
> }
>
> request.send(null)
>
> function ajaxRequest()
> {
> try:
> {
> var request = new XMLHttpRequest()
> }
> catch(e1)
> {
> try
> {
> request = new ActiveXObject("Msxml2.XMLHTTP")
> }
> catch(e2)
> {
> try
> {
> request = new ActiveXObject("Microsoft.XMLHTTP")
> }
> catch(e3)
> {
> request = false
> }
> }
> }
> return request
> }
>
>
> Firebug and the crome debugger doesn't say anything about any error, but it
> simply doesn't accomplish the tasck.
> Is there something wrong?
There doesn't seem to be any Prototype in this code snippet. For example,
Prototype would have $('theId') in place of document.getElementById('theId')
everywhere. This whole thing could be written in very few lines using the
Prototype Ajax methods. Have a look at the documentation at
http://api.prototypejs.org for a crash course.
Are you sure you aren't getting any errors with this code, though? It looks
like you're requesting data from another domain (unless you work at Yahoo) from
your own. You should be getting a security error because you're trying to load
content from outside of your page's domain.
Walter
> tab1ta
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/prototype-scriptaculous/-/LUOs7TBQ0TIJ.
> To post to this group, send email to prototype-scriptaculous@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.