Forum Moderators: open

Message Too Old, No Replies

AJAX submission problem with Prototype library

A form is submiting when I'd like it not to. I have a workaround, but...

         

dotancohen

6:08 pm on Nov 19, 2006 (gmt 0)

10+ Year Member



Hi all, I've got a form that I'd like to run through AJAX, using the Prototype library. However, whenever I try to run the form through Form.serialize() it gets submitted to the page specified in it's action attribute. For instance:

function sendFeedback(e) {
// Update user interface
$('response').innerHTML = 'Adding email address...';

// Prepare query string and send AJAX request
var pars = Form.serialize(addressForm);
var myAjax = new Ajax.Updater('response', 'ajaxServer.php', {method: 'get', parameters: pars});

// Stop form from submitting when JavaScript is enabled
Event.stop(e);
}


Causes the form to get submitted. However, when I replace:

var pars = Form.serialize(addressForm);

with:

var pars = 'address=' + escape($F('address'))+'&address2=' + escape($F('address2'));

The form then gets processed via AJAX as I intend. Why is that, and what can I do about it?

Thanks in advance.

Dotan Cohen

[edited by: encyclo at 6:16 pm (utc) on Nov. 19, 2006]
[edit reason] no personal URLs please, see forum charter [/edit]

dotancohen

5:06 pm on Nov 26, 2006 (gmt 0)

10+ Year Member



To interested parties, the problem weas in the lack of quotes. The code should have been:
var pars = Form.serialize('addressForm');