[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Thomas Heller
Sorry I got that totally wrong. The XHR actually follows redirects, it just 
doesn't do it like the browser usually does and does not change its location.

The response you are seeing is the final result of the redirect, eg the content 
of /person. You cannot cancel the redirect either as far as I'm aware.

You'll probably need to change the server side response.


On Saturday, September 12, 2015 at 8:53:59 PM UTC+2, Hari Krishnan wrote:
> On Saturday, September 12, 2015 at 2:11:31 AM UTC-7, Thomas Heller wrote:
> > You are using an ajax request which does not follow the same rules as a 
> > normal browser navigation requests. It will not follow redirects for 
> > example.
> > 
> > I don't know what ajax lib you are using but the general solution will be:
> > 
> > fire request
> > wait for response
> > check response code of request
> > if redirect get location header
> > do cleanup of your local app
> > then set document.location.href to location url
> > the page will unload and load /login as "normal"
> > 
> > or you could rewrite the server to not send a redirect but send the 
> > location encoded as data.
> > 
> > HTH,
> > /thomas
> > 
> > 
> > 
> > > 
> > > The response to curl is as follows:
> > > 
> > > HTTP/1.1 302 Found
> > > Server: undertow
> > > X-XSS-Protection: 1; mode=block
> > > Location: http://localhost:3000/login  <-
> > > X-Frame-Options: SAMEORIGIN
> > > Date: Fri, 11 Sep 2015 21:06:28 GMT
> > > Connection: keep-alive
> > > X-Content-Type-Options: nosniff
> > > Content-Type: text/html; charset=utf-8  <
> > > Content-Length: 0
> > > 
> > > However, the reagent form is not getting redirected to he /login form.  
> > > It remains in the same form.  On the console, I can see, however, the 
> > > login page is streamed as an HTML. ( I am using "/login" as just as an 
> > > example.).
> > > 
> > > The original reagent page is doing a request with CLJS-AJAX POST.
> > > 
> > > Any hint is much appreciated.  Thanks,
> > > 
> > > Regards,
> > > Hari
> 
> Hi Thomas,
> 
> Thanks for the answer.  I still have one more issue related to this logic.  
> When I set the :location at the header onn the server side, what I see on the 
> client console (Chrome) is as follows (logging the response from the server): 
>  I don't see the location key/value, instead, I see the whole page in HTML.  
> Any hint?  tried with different doc-types.
> 
> {:status 200, 
>   :success true, 
>   :body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
> --\r\n", 
> 
> :headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
> "nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", 
> "content-type" "text/html; charset=utf-8", "connection" "keep-alive", 
> "content-length" "3928", "x-xss-protection" "1; mode=block"}, 
> :trace-redirects ["/person" "/person"], 
> :error-code :no-error, 
> :error-text ""}
> 
> ON THE Client side, I solved the redirect issue with the following code:
> 
> (.assign js/location "/job")
> 
> But I couln't find the location in the header.  So I hard-coded it here!
> 
> Thanks for the response.
> 
> Regards,
> Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Hari Krishnan
On Saturday, September 12, 2015 at 2:11:31 AM UTC-7, Thomas Heller wrote:
> You are using an ajax request which does not follow the same rules as a 
> normal browser navigation requests. It will not follow redirects for example.
> 
> I don't know what ajax lib you are using but the general solution will be:
> 
> fire request
> wait for response
> check response code of request
> if redirect get location header
> do cleanup of your local app
> then set document.location.href to location url
> the page will unload and load /login as "normal"
> 
> or you could rewrite the server to not send a redirect but send the location 
> encoded as data.
> 
> HTH,
> /thomas
> 
> 
> 
> > 
> > The response to curl is as follows:
> > 
> > HTTP/1.1 302 Found
> > Server: undertow
> > X-XSS-Protection: 1; mode=block
> > Location: http://localhost:3000/login  <-
> > X-Frame-Options: SAMEORIGIN
> > Date: Fri, 11 Sep 2015 21:06:28 GMT
> > Connection: keep-alive
> > X-Content-Type-Options: nosniff
> > Content-Type: text/html; charset=utf-8  <
> > Content-Length: 0
> > 
> > However, the reagent form is not getting redirected to he /login form.  It 
> > remains in the same form.  On the console, I can see, however, the login 
> > page is streamed as an HTML. ( I am using "/login" as just as an example.).
> > 
> > The original reagent page is doing a request with CLJS-AJAX POST.
> > 
> > Any hint is much appreciated.  Thanks,
> > 
> > Regards,
> > Hari

Hi Thomas,

Thanks for the answer.  I still have one more issue related to this logic.  
When I set the :location at the header onn the server side, what I see on the 
client console (Chrome) is as follows (logging the response from the server):  
I don't see the location key/value, instead, I see the whole page in HTML.  Any 
hint?  tried with different doc-types.

{:status 200, 
:success true, 
:body "\r\n\r\n\r\n\r\n  \r\n  \r\n  
--\r\n", 

:headers {"date" "Sat, 12 Sep 2015 18:27:30 GMT", "x-content-type-options" 
"nosniff", "server" "undertow", "x-frame-options" "SAMEORIGIN", "content-type" 
"text/html; charset=utf-8", "connection" "keep-alive", "content-length" "3928", 
"x-xss-protection" "1; mode=block"}, 
:trace-redirects ["/person" "/person"], 
:error-code :no-error, 
:error-text ""}

ON THE Client side, I solved the redirect issue with the following code:

(.assign js/location "/job")

But I couln't find the location in the header.  So I hard-coded it here!

Thanks for the response.

Regards,
Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-12 Thread Thomas Heller
You are using an ajax request which does not follow the same rules as a normal 
browser navigation requests. It will not follow redirects for example.

I don't know what ajax lib you are using but the general solution will be:

fire request
wait for response
check response code of request
if redirect get location header
do cleanup of your local app
then set document.location.href to location url
the page will unload and load /login as "normal"

or you could rewrite the server to not send a redirect but send the location 
encoded as data.

HTH,
/thomas



> 
> The response to curl is as follows:
> 
> HTTP/1.1 302 Found
> Server: undertow
> X-XSS-Protection: 1; mode=block
> Location: http://localhost:3000/login  <-
> X-Frame-Options: SAMEORIGIN
> Date: Fri, 11 Sep 2015 21:06:28 GMT
> Connection: keep-alive
> X-Content-Type-Options: nosniff
> Content-Type: text/html; charset=utf-8  <
> Content-Length: 0
> 
> However, the reagent form is not getting redirected to he /login form.  It 
> remains in the same form.  On the console, I can see, however, the login page 
> is streamed as an HTML. ( I am using "/login" as just as an example.).
> 
> The original reagent page is doing a request with CLJS-AJAX POST.
> 
> Any hint is much appreciated.  Thanks,
> 
> Regards,
> Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.


[ClojureScript] Re: "Redirect-after-post" using secretary?

2015-09-11 Thread Hari Krishnan
On Tuesday, December 2, 2014 at 3:45:52 AM UTC-8, Russell Dunphy wrote:
> I'm trying to get my head around structuring my client-side routes (in a 
> reagent app) using secretary, and I'm struggling to work out the best way of 
> dealing with the "redirect-after-post" scenario where I have a form that is 
> submitted via AJAX, and once the AJAX request has successfully completed, I 
> want to change to a different page to view the saved record.
> 
> The two ways I can think of to achieve this are:
> 
> 1. Have the on-click event of the submit button make the ajax request, and 
> have the success handler call secretary/dispatch! to the new page.
> 
> This has the disadvantage of not changing the url hash, so links back to the 
> form don't work until you've changed pages again normally.
> 
> 2. Replace the submit button with an anchor tag pointing at a different 
> secretary route, something like /my-model/create, which makes the POST 
> request and renders the new page. The problem with this approach is that you 
> have to get the form data to the secretary route somehow, either by having it 
> as params on the URL, which seems a bit pants, or by having it in a state 
> atom that both the form and the secretary route knows about (which seems like 
> data that shouldn't be shared).
> 
> How are other people doing this? Am I on completely the wrong track?
> 
> Thanks,
> 
> Russell

Hi Russell,

Have you got this problem solved?  ( I would think you have as it is long time 
back.).  Would you mind posting your resolution here?  Thanks in advance.  I am 
facing a similar issue here.

The response to curl is as follows:

HTTP/1.1 302 Found
Server: undertow
X-XSS-Protection: 1; mode=block
Location: http://localhost:3000/login  <-
X-Frame-Options: SAMEORIGIN
Date: Fri, 11 Sep 2015 21:06:28 GMT
Connection: keep-alive
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8  <
Content-Length: 0

However, the reagent form is not getting redirected to he /login form.  It 
remains in the same form.  On the console, I can see, however, the login page 
is streamed as an HTML. ( I am using "/login" as just as an example.).

The original reagent page is doing a request with CLJS-AJAX POST.

Any hint is much appreciated.  Thanks,

Regards,
Hari

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.