View Full Version : Might be simple, might not

08-14-2007, 01:20 AM
I discovered Ajax a couple weeks ago and so far I'm impressed. I've been writing my own library and it seems to be working out well for me. My server side programs return an xml document and my client-side javascript parses that and takes appropriate actions. Working great so far.

I think this is pretty typical... the set up could be depicted as follows:
step 1.1 (client) ajax call using GET method -----> (server)
step 1.2 (client) <------------------- xml response (server)

As we all know, Ajax won't submit a file. So I'm going the regular form submission/response goes to hidden iframe strategy. I've written a routine that accepts the uploaded file and sends back a small html document with an onload() event to kick off the ajax submit. This currently looks like this:

step 2.1 (client) form submit using POST method -----> (server)
step 2.2 (client) <--- response via onload() in iframe (server)
step 2.3 (client) ajax call using GET method --------> (server)
step 2.4 (client) <---------------------- xml response (server)

Now the problem... or rather... what I'd like to do... is use an xml response for step 2.2 rather than the small html document. Or maybe there is a way to wrap my xml reponse up in the small html document. My goal is to be able to utilize the same function I wrote (that handles steps 1.2 and 2.4) to handle step 2.2 as well.

Any ideas?

Thanks in advance,

08-14-2007, 05:16 AM
My suggestion is look at what other libraries are doing to see how they work. Prototype.js is a good example.


08-14-2007, 07:40 PM
Ok, I found a way to kick off a function within an xml document. It just goes like this:

<script type="text/javascript" src="/mylibrary.js"></script>
<script type="text/javascript">

Now I just need myFunction to be able to grab the whole contents of the frame it is on. I thought I could just do a document.body.innerHTML but I have discovered that innerHTML does not work with an XML document (doh!). I've been trying to find the JavaScript command that will give me what I'm after, but I'm not having any luck right now.

Thanks in advance,