jQuery - Redirect with post data

前端 未结 12 1592
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 20:14

How can I redirect with post data?

How to move to new page with $_POST?

How to do this? How is it done and whyfore shall it be done

12条回答
  •  情歌与酒
    2020-11-28 20:44

    "extended" the above solution with target. For some reason i needed the possibility to redirect the post to _blank or another frame:

    $.extend(
       {
           redirectPost: function(location, args, target = "_self")
           {
               var form = $('
    '); form.attr("method", "post"); form.attr("action", location); form.attr("target", target); $.each( args, function( key, value ) { var field = $(''); field.attr("type", "hidden"); field.attr("name", key); field.attr("value", value); form.append(field); }); $(form).appendTo('body').submit(); } });

提交回复
热议问题