Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  142] [ 2]  / answers: 1 / hits: 19515  / 10 Years ago, sun, november 2, 2014, 12:00:00

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 (inside an HTML page, but outside the context of a form).



Is this possible as HTTP POST instead of GET request (kind of XMLHttpRequest plus replace the currently shown document)? How could I replace the document, if XMLHttpRequest must be employed (instead of window.location.href)? The second question has been partially answered here.


More From » rest

 Answers
57

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();

[#68942] Thursday, October 30, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
triston

Total Points: 545
Total Questions: 88
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;