AJAX form submision problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
dotancohen
Forum Newbie
Posts: 11
Joined: Thu Aug 04, 2005 5:37 am
Location: Haifa
Contact:

AJAX form submision problem

Post by dotancohen »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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:
[syntax="javascript"]
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:

Code: Select all

    var pars = Form.serialize(addressForm);
with:

Code: Select all

    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
http://what-is-what.com/what_is/ajax.html


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply