Skip to main content

My first problem with AJAX

I was using Callback (AJAX) to retrieve a page i had developed .
Lets start all over,
I was using AJAX to retrieve a part of the contents of a web page. Cool, simple, it downloaded without a pain, then I innerHTMLed it to a span tag. Worked fine, successful, clapped my hands etc.etc.

Clicked on the button which had seemed to appear out of nowhere.
And then, it all fell apart.
The feared exclamatory symbol appeared on the status bar.... And for the newbies, thats an indication of a JavaScript error in IE.
Of course, as usual i was all curses at my IE window......Anyway to make a long story short (i AM quite sleepy u know). the scripts which i seemed to be innerHTMLing to the span tag are not executed. And what i mean is anything between the script tags which have been innerHTMLed to that span tag are not executed.

Of course i can see a ray of hope in the distance. I mean the distance till tomorrow morning.


And just for kicks, check out a hi-fundoo flash file titled EPIC 2004 .
And for all the Indians out there, Check out Param Padma. 1 TeraFlop/second.
For the non-indians of course there is Earth Simulator, Japan's 40-Teraflop/second.

Comments

Rakesh Pai said…
I wonder if you fixed this problem. It would be nice to share your solution with us.

If you haven't solved it yet, the problem might be your markup's doctype, if you are serving as XHTML. You can't innerHTML text into a XHTML document. In fact, the XHTML DOM doesn't have an innerHTML function at all!

Instead, you should use the DOM methods (like createElement) to create the markup you need.

It's logical, if you think about it. If you innerHTML text into a XHTML document, you might break the XML structure of the document. Using the DOM functions, you can never break the XML structure.

Of course, all of this is not a problem if you are using HTML. HTML is not valid XML anyway!

By the way, if you are using XHTML, don't use IE! IE doesn't even support XHTML. It thinks it is HTML and proceeds to render it like any HTML page. Not usually a problem, but you don't really have any of the benefits of XHTML that way, and you would never know (unless you validate) if your markup is ill-formed.

Actually, just stop using IE anyway. Get Firefox! And one you have the JS-related extensions installed, you'll see how easy it is to develop client-side code. :)
Rakesh Pai said…
Disregard everything I said. It was said in one of those moments of utter stupidity. It is stupid, because:

1. Since IE renders XHTML as HTML, innerHTML is supported with any document type anyway.
2. Most recent versions of Firefox have support for innerHTML with XHTML documents, provided the string you are adding is a valid XML snippet.
Sachin Nayak said…
Disregarded, etc.etc. Anyway I think i may have stumbled on a solution. I am retrieving srcipts using AJAX, looping thru them using getElementsByTagName(as i have tags other than script tags). eval'ing the contents of all script tags which have no src attribute. If they have a src attribute, a new script element uis created, and added appropriately. This seemed to work for the samples i had tried for. I do need to check with the real code.
Sachin Nayak said…
This comment has been removed by a blog administrator.

Popular posts from this blog

The fight is in the open

Been busy lately and so have not managed to post for quite long. But I just had to post this. This post is dedicated to all persons who dont know anything about the fight between MS and Google: Check out the links starting from: http://news.zdnet.com/2100-9588_22-5875433.html?tag=nl.e589 There are more links as you get thru the article. Be sure to read those too. And just as a side-note: Check out " Atlas ". These are client side and server side components, which easily (??) enable you to make Web calls. This is done by encapsulating AJAX. (please dont insult by telling me that you dont know what that is).

Finally decided

I have been having these various itch since quite some time. Both about what i am doing here (where i work) and what am i meant to do. Finally, i have decided "I need a job change". I guess IT services industry was never meant to be the right industry for me. Don't get me wrong there, it's not that i wanna quit because i am not getting any interesting work, it's just that I have ideas about life which does not match with what my company is doing. (As amatter of fact, they have some really beautiful concepts which are great to work on). But i have believed web to be the future and now i have started realising that personal dreams do become quite a pain in the neck, when they are ignoired. Huh.... now that i put it on a log, i feel much better. Back to work...

Movies common for 2 actors/actresses

One question: Which all movies did both George Clooney and Brad Pitt act in? Am sure you would be going to google. And what do you do after that? See all the links, and check each and every page, trying to find the common movies. Now why could the computer not do this? Why are you spending 5 minutes trying to find this out, when you should be able to request the computer to do this..... Enter Semantic search, a mechanism where you can query data for relationships which the human mind understands, and secondly the computer understands. There are many places where they are trying to build this semantic search. I build a small application which uses freebase . And built an application where you can provide the names of 2 actors/actresses and find the movies both worked on. Check the page http://www.nlighten.in/CommonMovies.html . Details about freebase: Freebase uses the databases provided by Wikipedia and multiple other providers, and provide all the data in OOP ...