Broken history for a self-updating form using post-redirect-get - browser-history

I have a URL /books, which lists some books, and a URL pattern /books/{some-book-title} which shows a view/update form for the metadata of a book. Here's a typical user story, where a user corrects an incorrect author entry:
GET /books
Ulysses
Don Quixote
GET /books/ulysses
<form action="/books/ulysses" method="post" enctype="application/x-www-form-urlencoded">
<input name="author" value="Jamessss Joycessss">
</form>
POST /books/ulysses FORMDATA author=James+Joyce
Redirect 303 SEE OTHER location = /books/ulysses
GET /books/ulysses
<form action="/books/ulysses" method="post" enctype="application/x-www-form-urlencoded">
<input name="author" value="James Joyce">
</form>
The problem is that the history stack is now
/books
/books/ulysses
/books/ulysses
so that when the user presses "back", they don't go back to /books, they just refresh the current page. Is there a non-javascript way to handle the update case so that the back button has the expected behavior? And if not, what's the javascript way to fix this?
EDIT: even more confusing if you post multiple times
GET /books
GET /books/ulysses author=Jamesss Joycesss
POST author=3 -> redirect shows author=3
POST author=2 -> redirect shows author=2
POST author=1 -> redirect shows author=1
Press back button /books/ulysses shows author=1
Press back button /books/ulysses shows author=2 (!!!)
Press back button /books/ulysses shows author=3 (!!!)
Press back button /books

A JavaScript way of modifying behavior of back button would be to use the history API
Here is a quick way to go to first page in the history stack. Just add an Event listener for back button and use history API.
window.history.go(0);
Have a look at the API : https://developer.mozilla.org/en-US/docs/Web/API/History_API

Related

webview2 vb.net accept cookies button press

I previously used the old ie based control
But have a new project getting data from a web page
Its a login page so im hoping to use the control to grab login then get the relevant data then log out.
However when loading the page in the control the html elements dont apear to have an id.
The first problem I have is the accept cookie button which in dev tools shows as
<a class="acceptAllButtonLower" tabindex="0" role="button" aria-hidden="false" style="">Accept All</a>
Next button to press is
<button class="sign-in-btn" ng-click="vm.signIn('\\',true)">
SIGN IN
</button>
i have tried
WebView21.CoreWebView2.ExecuteScriptAsync("document.getElementsByClassName('acceptAllButtonLower')[0].click();")
and
WebView21.ExecuteScriptAsync("document.getElementsByName('acceptAllButtonLower')[0].click();")
with no luck.
Im not even sure the click is being passed etc.
Can someone kindly point me in a better direction.
Ta
Have tried the above with no success

how to restore URL after clicking the backbutton?

My /htmx webpage has a list of links like this one:
<li class="collection-item" hx-push-url="true" hx-post="/htmx/file/open/specification.idp"
hx-trigger="click" hx-target="#screen">Click me</li>
When I click it, the #screen target is correctly updated, and the browser URL is correctly changed to /htmx/file/open/specification.idp (thanks to hx-push-url="true").
When I click the browser back button, the original htmx page is properly displayed, but the browser URL remains /htmx/file/open/specification.idp, instead of becoming /htmx.
How can I get the browser URL to be /htmx? I'm using Htmx 1.8.0. I also tried using hx-get.

notify_url no longer working

This has been working for years then about 6 weeks ago or so the notify_url is no longer called, my form/post code looks like this:
<form id="payme" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="return" value="http://www.houdinistop.co.uk/Thanks.aspx" />
<input type="hidden" name="notify_url" value="http://www.houdinistop.co.uk/Payment/Receive_PayPal.ashx" />
I have a bit of code on the ashx page which will send me an email if the page is hit, and if i go to the ashx page in my browser i get the email, but following a paypal transaction it never calls the handler.
It used to work and I made no changes and now it doesnt work so I'm guessing paypal changes something but all my Googling efforts cant find any info
Do notify_url setting in bussiness a/c of paypal
In addition to email notification, PayPal can send you the transaction data (also called Instant Payment Notification) to a specific url. With Instant Payment Notification, PayPal sends payment notification messages with encrypted code to the specified URL for each payment you receive. Follow the instructions below to setup Instant Payment Notification.
Go to the PayPal website and log in to your account.
Click "Profile" at the top of the page.
Click "Instant Payment Notification Preferences" in the Selling Preferences column.
Click "Edit IPN Settings."
Enter the notification URL and select "Receive IPN messages."
example: http://www.houdinistop.co.uk/Payment/Receive_PayPal.ashx
Click "Save."

How to make submit form which goes to the same page in Joomla

I am making form with submit button in Joomla custom HTML and I would like to stay on the same page after I click on the submit button.
Is that possible? Thanks in advance.
Just leave the form action attribute out. This will post back to the same page. Have a look at this question and answer: Is it a good practice to use an empty URL for a HTML form's action attribute? (action="")
If "stay on the page" means that the page will not reload, or anoter page will be loaded, yes, thats quite possible. I think the best way of doing this is replacing the <input type=submit> with a <button>, which calls a javascript function that evaluates the form, submits the data via ajax, and notifies the user that the form was successfully submitted.

Disable Page Cache to force page load with browser back button

I have an asp.net website that is using update panels on the page that i cant get to reload from the server. I have this for the disable page cache on the master page.
Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
Response.Cache.SetValidUntilExpires(False)
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()
When I click the browser back button to go back to the page it says the page has expired. The other pages on my web site work and call the page load, the only solution i found but cant use is to wrp the whole page in an update panel, but i can't do this because i have a report viewer on the page that does not work with ajax. If anyone can help i would deeply appreciate it.
This is not a browser cache problem; it's a postback one. You have to implement the Post/Redirect/Get pattern in order to avoid the "do you want to submit again? / page expired" message.
http://en.wikipedia.org/wiki/Post/Redirect/Get
The classic example for this thing is when a web page has a save button that insert something in a Database. The "Save" button is clicked -> a postback occurs -> code insert a row in a table -> user refres the page (F5) -> postback occurs again -> code insert the same row again.
To avoid the double insert in the previous example you need to redirect when the "save" button is pressed and only then, execute the insert.
Just add this in your view file in header part:
<head>
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>
</head>
Inside body tag add this:
<body onUnload="OperaReload()">
<input type="hidden" id="refreshed" value="no">
To reload the page with JavaScript use the following:
window.location.replace(window.location.pathname);