| View previous topic :: View next topic |
| Author |
Message |
ovigo22
Joined: 15 May 2006 Posts: 130
|
| Why do people use XMLHttpRequest when creating a new script object and appending it to the body in some cases seems so much natural? |
| |
|
|
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| I don't understand what you're asking |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
| What i'm asking is what's the for/against on using XmlHttpRequest versus something like var script = document.createElement("script"); script.src = "somefile.js.php?info=abc&param=xyz"; document.body.appendChild(script); |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
You can't do that, for one.
Security mechanisms prevent it |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
Why not?
No they don't
I've done it |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
Because that would open up a huge can of cannibalistic worms
Okay, show me. |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
| Erm. where? |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| Wherever you did it |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
| On my private intranet... |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| Ha |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
Ha what?
I'm not making this up |
| |
|
|
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
Ha you're full of shit.
Yes you can do that, yes you can set whatever attributes yo uwant
But it won't work
It won't parse the script |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
Yes, it does, on IE and FF. and i'll back up that claim if you give me a moment. This page details what i just said: http://www.webreference.com/programming/ajax_tech/
Huh, well.. it has been working fine for me. given that, is it better/worse than other methods? |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
I was thinking oScript.innerHTML = "blah blah blah"
You can't do innerHTML on a script element. My bad. |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
Okay
That's ok. so anyway, seems to me that a lot of time you want to kick of some javascript after you get your data, so why not do it this way, where the JS file returns the data plus a statement or two that gets the page updated? |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
I've never been able to get <script></script> code to parse that comes from an ajax request
Ie, updating a div with <script></script> elements |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
This isn't coming from an ajax request if you mean XmlHttpRequest... it's a new script element that requests a file with parameters, on the server side some language like PHP could generate the javascript for the request
Do you get my meaning |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| So what issues is it giving you? |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
No issue, i was just wondering why it doesn't seem more widely used since it seems like a pretty good technique for me. maybe there's something i'm not aware about
Anyway it works for me and it seems standards compliant so i think i'll employ it when appropriate
By default it'll block if you are doing it on your local machine
But it shoudl work on a web site by default afaik |
| |
|
|
|