开发者

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

开发者 https://www.devze.com 2023-03-27 06:45 出处:网络
$.post(\'/ur.l\' , jQuery(\'selectors\').serialize() + \'&textareaname=" + escape( $("#textarea").val() )
    $.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 se开发者_开发百科rialize 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()
    


  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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号