vol7ron
vol7ron

Reputation: 42099

jQuery: Possible to use object and serialize for passing parameters?

    $.post('/ur.l'
          , jQuery('selectors').serialize() 
                               + '&textareaname=" + escape( $("#textarea").val() )
          , function(data) { ... } 
          }
    );

    $.post('/ur.l'
          , {'foo':'bar', 'foobar','qazbar'}
          , function(data) { ... }
    );

Problems

  1. Is it possible to combine the object into {...} the jQuery serialization?

  2. jQuery doesn't seem to serialize textareas, is there a better method than the above? I've tried and see that the textarea is in the jQuery object, but the text is blank:

    jQuery('input, textarea').serialize()
    

Upvotes: 2

Views: 2009

Answers (2)

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

  1. jQuery.param will serialize an object into a url encoded string. You can then combine them together.

  2. serialize does works with textareas. Make sure you have a valid name on the textarea, and that it is not disabled.

Upvotes: 4

dreuv2
dreuv2

Reputation: 23

You should try and give your form an id and refer to the form parameters through that. For example if you form was had an id of #form.

$("#form").submit( function () {    
    $.post(
   'ur.l',
    $(this).serialize(),
    function(data){

    });
    return false;   
  });   
});

and $(this) will be the contents of all of your form parameters. Also in case you are not doing so already, take a look at the headers.

Upvotes: 0

Related Questions