[removed].href with POST instead of GET (or equivalent effect)

后端 未结 1 1986
北恋
北恋 2021-01-20 03:34

I\'d like to reload a web page after supplying new parameters to it via POST in the same way as would be possible with an HTML form but from within JavaScript (

相关标签:
1条回答
  • 2021-01-20 03:38

    The way I have always done this (with jquery) is this.

    var $form=$(document.createElement('form')).css({display:'none'}).attr("method","POST").attr("action","URLHERE");
    var $input=$(document.createElement('input')).attr('name','FIRST NAME HERE').val("FIRST VALUE HERE");
    var $input2=$(document.createElemet('input')).attr('name','SECOND NAME HERE').val("SECOND VALUE HERE");
    $form.append($input).append($input2);
    $("body").append($form);
    $form.submit();
    
    0 讨论(0)
提交回复
热议问题