在jquerypost中同时传递表单对象和一个变量

passing form object and a variable at the same time in jquery post

本文关键字:变量 一个 单对象 表单 jquerypost      更新时间:2023-09-26

我知道这个问题可能有点出于好奇,但请帮助我理解,因为我已经对此进行了研究,但可能需要解释,因为不够清楚

是否可以在jquerypost中同时传递一个表单对象和一个变量例如

var review=$('#review').val();
var post_url="url.com";
$.post(post_url,{'review':review, $('#registration_form').serialize()},     function(returned_form)
     {           
         $('#show_items').html(returned_form);
    });

上面的代码能很好地工作吗

是的,您可以传递多个值。你只需要命名每一个:

var review=$('#review').val();
var post_url="url.com";
$.post(post_url,
       {
         'review': review, 
         'registrationForm' : $('#registration_form').serialize()
       },
       function(returned_form) {           
         $('#show_items').html(returned_form);
       }
);