[nycphp-talk] Thoughts on using JavaScript with no progressive fall-back
csnyder
chsnyder at gmail.com
Wed Feb 28 15:11:09 EST 2007
On 2/26/07, Chris Shiflett <shiflett at php.net> wrote:
> What's the best-of-breed solution for changing a regular form submission
> button to initiate an Ajax call instead of submitting the form? I've got
> a hacky solution that involves rewriting the button, adding an
> onsubmit() action, and trying to keep it from submitting the form in IE,
> but it feels like there must be a more elegant solution.
>
That's why I used the word "mojo" -- it's not the name of a new
framework, it's a description of the approach. Or as you say, hacky.
I leave form buttons intact, and just change the form's target
attribute to submit to a hidden iframe. I prefer that method since it
allows file upload, whereas XMLHttpRequest form submission does not.
Getting the response out of the iframe is also hacky, but iframes
generate an onload event. The code to actually get the content out is
platform dependent:
function iframeonload() {
var ifdoc = $("hiddenIFrame").contentDocument ||
document.frames("hiddenIFrame").document;
// etc...
}
What you _don't_ get with iframes is any sort of intelligent HTTP
error handling.
--
Chris Snyder
http://chxo.com/
More information about the talk
mailing list