On 2/26/07, Chris Shiflett <[EMAIL PROTECTED]> 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/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to