Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. My current solution is to return and then the client does window. Redirects on ajax calls don't work, browsers do not honor them. See this question for some good examples. As a side note, POSTing the login form via ajax does not really give you much of an advantage, I would let the browser POST the form normally and then your Flask view function redirects to a new page on success or redirects back to the login page on failure, possibly with a flash message to inform the user of the error.
No reason use redirect with ajax because it will return redirected content in your case just content with index endpoint. So you can return link to redirect if all ok status instead real redirect:. Learn more. How to redirect with Flask and jQuery Ask Question. Asked 6 years, 10 months ago. Active 2 years, 2 months ago.
JQuery Ajax Post Request Example in Laravel 5.7
Viewed 10k times. I'm using Flask as my backend and jQuery for a personal project I'm working on. My question is: Is there some way I can intercept make the client redirect? I assume the issue is because jquery is initiating the request and not the browser. Why are you using AJAX if you want to duplicate the behavior of a regular form? Also, don't store plaintext passwords.
Hash them. You might want to have a look at Flask-Login for this task. It is probably going to be more secure than most self-built auth systems.
Active Oldest Votes. Miguel Miguel Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Featured on Meta. Feedback on Q2 Community Roadmap. Technical site integration observational experiment live on Stack Overflow. Dark Mode Beta - help us root out low-contrast and un-converted bits.
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up. The method is hit and the related items are also present in the content tree. But nothing happens.
The current page remains and no redirection occurs. Also, there are no errors or messages in the browser console.
This means that your success handler will be called only when the browser issues a second request and loads the page it was redirected to. So you should not attempt to use redirect response codes in AJAX calls.
Instead, I suggest that you return a custom object containing the redirect URL:. Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 3 years, 4 months ago. Active 3 years, 4 months ago. Viewed 17k times. I am using Sitecore 8. I am trying to perform a page redirect, but my code isn't working.
GetItem currentItemGuid ; if pageItem! This item is present in the content tree in the same folder structure. Dmytro Shevchenko Qwerty Qwerty 2, 1 1 gold badge 13 13 silver badges 43 43 bronze badges.
Please check what response you see in the Network tab of Chrome Development Tools. Find the AJAX request in the Network tab, click on it and see what is contained in the response headers.
It says ok for status, the type is xhr and the initiator there is the url - http:mysite.
Qwerty Have you tried debugging the method? It looks like it always goes to the else branch. Probably, the item is not found. DmytroShevchenko No. I checked that. The pageItem is not null and it hits the return Redirect with new url. Can you decorate your controller with [AllowAnonymous]? Just to try, I don't know if it helps.NET technology more specific and detailing: from the server side not client sideand as years go by and technologies arise the same need is required for ASP.
Of course I would recommend you to read that article for more explaination on the matter, because it will give pretty much detailed insight on why do I have all these solutions, of course thats up to you to read. The whole idea of redirect and post in ASP. NET was simple and neat: in code behind server side whenever we want to do a redirect and post we simply create an html form with http POST method and the url is set to destination url, we create a hidden field for each value we want it to be posted to destination url and we create a simple script block that will run once the whole html page is inturpretted, and the whole thing is returned in the response so it can be ran later by the browser of which it will do redirect and post.
In ASP. NET it was in a helper method takes Page instance as a parameter :. The only difference from my side is that this time I added this peice of code to a library of mine called Fluentx. Mvc it has a dependency on Fluentx and you are good to go. Now to the action: to do redirect and post for ASP. Mvc in your controller, secondly add the code below similar of course to where it fits your application:.
Just note that the below method RedirectAndPost is an extension method, so make sure you have the reference to Fluentx. Mvc namespace in your c file. Nothing much to mention except the limitations of this solution as I have already mentioned this in my other article and I am qouting my self 5 years later:.
If I am asked what the drawbacks of this solution are, I would say maybe one drawback I aslo recommend you to have a look at Fluentx project, its a small project of mine that has a lot of helper classes and extension methods plus a great simple object to object mapper and many many other stuff c control statements, specification pattern for internal business rules NET developers.
Nuget package as Fluentx. Mvc Recommended.
I did some research on this topic, and there are some experts who have said that it is not possibleso I would like to ask for an alternative solution. Inside process.
Your data will be sent to Page C without much hassle to the user. This is the only way to do it. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The only way to achieve what you're doing is with a intermediate page that sends the user to Page C.
Simply use an AJAX request on Page A to go and generate your invoice number and customer details in the background your previous Page Bthen once the request gets returned successfully with the correct information - simply complete the form submission over to your payment gateway Page C.
This will achieve your result of the user only clicking one button and proceeding to the payment gateway. Below is some pseudocode. I think the simplest would be to actually let the user do the POST.
Redirect and POST in ASP.NET MVC
Redirect to another page using Post method from code behind in ASP. Net using C and VB. HTML Markup. The values of these TextBoxes will be posted to new page from code behind. First Name:. Last Name:. You will need to import the following namespaces. Imports System.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I want the success on ajax post to go to the home page. For some reason I keep doing it wrong. Any idea what I should do to fix this? Not sure why, but window. I ended up using window. Learn more. Redirecting after Ajax post Ask Question. Asked 6 years, 8 months ago. Active 1 year, 8 months ago.
Viewed 69k times. Alain Goldman Alain Goldman 2, 4 4 gold badges 36 36 silver badges 67 67 bronze badges. Do you see any messages in the browser's console? Active Oldest Votes. FakeRainBrigand, yes indeed. Recently i received one downvote thats why.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. After including JQuery and the jquery. This needs clarification. Is your server handling a POST that you want to redirect somewhere else?
It's probably a good idea to make a link that says "click here if not automatically redirected" to deal with pop-up blockers. I included the jquery. Learn more. Asked 6 years, 6 months ago. Active 1 year, 1 month ago. Viewed k times. How can I redirect with post data? How to do this? How is it done and whyfore shall it be done. I am actually very interested to hear this answer. It's not possible to set the windows location with a POST request, only GET requests, and it's not possible to redirect a POST request, so the usual solution is to dynamically create a form with the needed data and action attribute, and submit it.
Active Oldest Votes. Black 9, 16 16 gold badges 75 75 silver badges bronze badges. Tim S Tim S 2, 13 13 silver badges 22 22 bronze badges. TimS, after checking out that link, I am still unclear as to how you can retrieve the data in the new page using post. Great suggestion! Using jquery 2. Here's a simple small function that can be applied anywhere as long as you're using jQuery.
JimTheDev 3, 1 1 gold badge 17 17 silver badges 25 25 bronze badges. This solution is much better than the accepted answer imo. It's easy to implement and no need for loading additional libraries! Great idea with extend.
Thus if value contains quotes, it does not work. Function itself can be replaced with one that is aware about quoting, like from here: stackoverflow. Why dont just create a form with some hidden inputs and submit it using jQuery? Should work :.