@steve.percy
i did what you suggest,i passed the params in the query, retrieve them in the
home view and place them in the template, but it is the same. maybe i did not
explained myself: the page does not render at all, it shows "print" message in
the view callable, it shows as xhr in the browser development tool but in
browserdoes not change url nor displays the page.
@jvanasco
i changed the javascript to this:
<script type="text/javascript">
function postit(){
console.log("pompom");
var xhr = new XMLHttpRequest();
xhr.open("POST", '/test', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
xhr.setRequestHeader("Upgrade-Insecure-Requests", 1);
xhr.send("prm_0=898&prm_1=603");
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
window.location.replace("/");
}
};
}
</script>
and it worked! thanks.
so, to make this clear to me: the POST made from javascript is not equivalent
to a POST made in html, the hmtl POST automatically refreshs page or something
like that?
thanks to both of you.
En Tue, 17 Jul 2018 02:45:07 -0500, Jonathan Vanasco <[email protected]>
escribió:
the issue is in your javascript; the browser will never render the template on
this setup.
when you view /test via GET (or missing one or more required POST items),
templates/jg.pt is rendered.
when you view /test via POST with both variables present, the response is a
redirect (HTTPFound)
your javascript submits "form data" but it's not submitting the form for the
browser. the response from pyramid is lost in javascript.
your flow is this:
* browser-tab GET /test
** browser-tab's javascript POST /test
** pyramid redirect to /home
** browser-tab's javascript ???
in this flow, the browser tab doesn't POST, the javascript engine in the tab
does.
because the POST happens within javascript, you need to use javascript to
decide what to do.
typically before hitting send, one would define a callback hook for the xhr
object, something like explained here:
https://www.w3schools.com/xml/xml_http.asp
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// do something with this.responseText;
console.log('got response');
}
};
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
[email protected]<mailto:[email protected]>.
To post to this group, send email to
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/cbfe7308-6176-4ffa-ba2c-238b686495fd%40googlegroups.com<https://groups.google.com/d/msgid/pylons-discuss/cbfe7308-6176-4ffa-ba2c-238b686495fd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
JG
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/DM6PR06MB4012CFE32BE47BE2DA115DC8955C0%40DM6PR06MB4012.namprd06.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.