serialize () or val ()?

  • The question is not correct. - .serialize () - returns a string, with the names and values ​​of the selected form elements - val () - returns the value attribute value of the selected form element. The method assignments are different, but what do you want to achieve? - Deonis

1 answer 1

If through AJAX then

$.ajax({ url : url, type : 'post', data : $('form').serialize(), success : function(data) { // получаем ответ в <div id="response"></div> $('#response').html(data); } }); 

If there is a select or radio in the form, then it will not be possible to send via .val (). If you just need to initiate the request, then

 $('form').submit(); 

If there is no jQuery then

 window.form[0].submit();