forcing a POST wo/ a form

A

Aryeh.Friedman

I want every page on my site to be requested using POST (when linked
from by myself)... namely almost all my pages call some kind of
backend and I *DO NOT* want the user to see any of the backend/
internal servlet names (yes I am using servlets, and no JSP is not a
real option for other reasons).... what I have right now is something
like this:

function send()
{
figure out the URL

location.href(url);
}

the only problem is location is a GET and not a POST and what I want
to do (without introducing forms) is force it to be a POST
 
E

Evertjan.

I want every page on my site to be requested using POST (when linked
from by myself)... namely almost all my pages call some kind of
backend and I *DO NOT* want the user to see any of the backend/
internal servlet names (yes I am using servlets, and no JSP is not a
real option for other reasons).... what I have right now is something
like this:

function send()
{
figure out the URL

location.href(url);
}

the only problem is location is a GET and not a POST and what I want
to do (without introducing forms) is force it to be a POST


function postwith (to,p) {
var myForm = document.createElement("form");
myForm.method="post" ;
myForm.action = to ;
for (var k in p) {
var myInput = document.createElement("input") ;
myInput.setAttribute("name", k) ;
myInput.setAttribute("value", p[k]);
myForm.appendChild(myInput) ;
};
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
};

source:
http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-
data-between-pages/

I suppose if you omit a target:
myForm.target="_blank" ;
you can forget about the remove.,
since the originam page will be gone.

not tested.
 
T

Thomas 'PointedEars' Lahn

I want every page on my site to be requested using POST (when linked from
by myself)...

No, you don't. Consider the hassle for the user when navigating back,
for example.
namely almost all my pages call some kind of backend and I *DO NOT* want
the user to see any of the backend/ internal servlet names (yes I am
using servlets, and no JSP is not a real option for other reasons)....
what I have right now is something like this:

function send()
{
figure out the URL

location.href(url);
}

the only problem is location is a GET and not a POST and what I want to
do (without introducing forms) is force it to be a POST

While it is possible to make POST requests with XHR, you have a problem
that cannot reasonably be resolved with client-side scripting.

Read on server-side URL rewrite instead, and also reconsider the design of
your Web application.


PointedEars
 
A

Aryeh.Friedman

(e-mail address removed) wrote on 29 jan 2009 in comp.lang.javascript:


I want every page on my site to be requested using POST (when linked
from by myself)... namely almost all my pages call some kind of
backend and I *DO NOT* want the user to see any of the backend/
internal servlet names (yes I am using servlets, and no JSP is not a
real option for other reasons).... what I have right now is something
like this:
function send()
{
          figure out the URL
          location.href(url);
}
the only problem is location is a GET and not a POST and what I want
to do (without introducing forms) is force it to be a POST

function postwith (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  };
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;

};

source:http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-
data-between-pages/

I suppose if you omit a target:
myForm.target="_blank" ;
you can forget about the remove.,
since the originam page will be gone.

not tested.

Thanks that did the trick... I only have one question now how do I
tell it to refresh/reload the page to the results of the submit()?
 
A

Aryeh.Friedman

(e-mail address removed) wrote on 29 jan 2009 in comp.lang.javascript:


I want every page on my site to be requested using POST (when linked
from by myself)... namely almost all my pages call some kind of
backend and I *DO NOT* want the user to see any of the backend/
internal servlet names (yes I am using servlets, and no JSP is not a
real option for other reasons).... what I have right now is something
like this:
function send()
{
          figure out the URL
          location.href(url);
}
the only problem is location is a GET and not a POST and what I want
to do (without introducing forms) is force it to be a POST

function postwith (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  };
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;

};

source:http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-
data-between-pages/

I suppose if you omit a target:
myForm.target="_blank" ;
you can forget about the remove.,
since the originam page will be gone.

not tested.

Thanks that did the trick... I only have one question now how do I
tell it to refresh/reload the page to the results of the submit()?
 
E

Evertjan.

function postwith (to,p) {
ÿ var myForm = document.createElement("form");
ÿ myForm.method="post" ;
ÿ myForm.action = to ;
ÿ for (var k in p) {
ÿ ÿ var myInput = document.createElement("input") ;
ÿ ÿ myInput.setAttribute("name", k) ;
ÿ ÿ myInput.setAttribute("value", p[k]);
ÿ ÿ myForm.appendChild(myInput) ;
ÿ };
ÿ document.body.appendChild(myForm) ;
ÿ myForm.submit() ;
ÿ document.body.removeChild(myForm) ;

};

source:http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-t
o-p ost-
data-between-pages/

I suppose if you omit a target:
myForm.target="_blank" ;
you can forget about the remove.,
since the originam page will be gone.

not tested.

[please do not quote signatures on usenet]
Thanks that did the trick... I only have one question now how do I
tell it to refresh/reload the page to the results of the submit()?

I believe a post request always results in a relaoad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,116
Messages
2,570,699
Members
47,274
Latest member
SeleneHgw8

Latest Threads

Top