I want to make the results of an ASP.NET form POST "bookmarkable", and I'm thinking of using query parameters to accomplish this.
The idea is that a user will visit http://domath.com and they will type in a math problem, and view the results. The query and results are visible at http://domath.com?ProblemID={some guid here}
The only part I don't really know is how do I change the target of the form URL since I'm using a POST instead of a GET..
Here are the options I came up with, and I'm not sure what is practical
Submit form as usual, server redirects to a URL with the new parameters attached
Use a webservice or callback to get new URL. Javascript then updates form target
The first option is the easiest and most common. It follows the Post/Redirect/Get model, which avoids double form submission in addition to letting you bookmark the resulting page.
Related
I have a site with loads of Javascript, where users input informations, which gets saved in Javascript objects on the site. I also have a working export/import from JSON - once the user fills out the form, he can "Export to JSON", and if he refreshes the page (and the form is cleared), he can "Import from JSON" and the forms get filled.
I want to also save the data into the URL, so the users can simply share the URL, and the forms will get pre-filled based on the URL content.
Closest example I was able to find is these old game calculators - http://classicdb.ch/?talent#Lsoedm0oZVx0f0xoZTMo
The information is encoded in the #Lsoedm0oZVx0f0xoZTMo and then processed and the form is filled.
How does one go about implementing this? Can I use the JSON import which I already have?
Thank you
If you're asking how to make the hash that could be part of the URL. This article might help you: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
In case you want to modify or receive the hash from URL, René's answer answered that already. :)
Appending the hash to the url should not be the question but receiving and processing, right?
For these javascript provides
location.hash
That way you will get the "Lsoedm0oZVx0f0xoZTMo" and do whatever you have to.
I was looking on how to get values of form data that are passed with POST requests and found this answer.
I know you you can get GET query parameters quite easily in JavaScript doing window.location.search but is there a way to do similar for POST request or document.forms is my only option?
To expand on what RUJordan said:
When you do a POST, the information is sent to the server using an entirely different method and does not show up in the URL or anywhere else that JavaScript can get access to it.
The server, and only the server, can see it.
Now, it is possible to take some of the form data and fill JavaScript variables and/or hidden form fields so the server can pass data back down to the client.
If you need more help, you'd be better off opening another question explaining exactly what problem you are trying to solve.
Do you want javascript to see the data was POSTed to load the current page?
JavaScript does not have access to the request body (where the POST content is) that loaded the page. If you want to be able to interact with the POSTed parameters, the server that received the request would need to respond with the necessary data written back out on the page where javascript can find it. This would be done after the form was submitted, as part of the response to that POST request.
Or do you want to know what your page could POST form the forms that are on it?
Inspecting document.forms will let you see what could be POSTed later if those forms were submitted. This would be done before the form was submitted, without a request being made.
I have a form that has a number of dependent parameters fields. That is, changing one parameters field value may cause a server request to repopulate the other parameter fields. After the user sets all of the fields they will press a button and launch in a popup window a new form running the report they specified.
To get the URL for this window I need to make one final call to the server which will return the formatted URL (using GET). So the resultant flow on button click is:
Gather values from fields
Call web service to construct URL. (I will use a promise)
Launch open.window with new URL
The first 2 steps are straight-forward, but I am unsure on how to handle the window.open from the controller. Any thoughts or ideas?
P.S.
I thought about using a directive to overwrite the link URL as values changes, but having to go back to server to construct the URL after each parameter changed seems like way too much processing.
Sorry for wasting people's time. The answer is $window.open() from the controller.
We are trying to implement a web page that each time of page refreshing will not result in the form resubmit, how to achieve that? Is there any Javascript code or HTML can make it WITHOUT external javascript library(jquery, dojo or extJs)
The reason of such design is that the form is going to tie an unique relation to current data with means cannot do it twice but for security reason we have to use POST instead of GET, also after the action we still want to preserve user the right to do similar action on the same page to another relation. so how to avoid a consequence like that?
Thanks.
Suppose that the action to the form submits it to submit_form.php. That file can handle the data and do whatever it needs to do. Then in it's response, it can redirect the browser to a separate page (you'll have to look up the exact method of how to do this depending on what language you write your POST handler in). This separate page can show the results of the form submit using session variables or some other method.
Effort
I've read this question, but I still think there has to be a way to do this client side.
Case
I'm submitting a form that has a few inputs. When the form is submitted, the primary key of those inputs is shown on a results page along w/ other data and a different form.
The effect I'm trying to do is if the input-pk is modified, I want it to reload the page (think window.location.reload()), only I want to update that PK parameter's value with the changed value.
window.location.reload takes one of two values (true/false), which distinguishes if it should use browser cache or not. Thus, it seems like it should be accessible, especially since the Firebug::Net plugin shows the param in the HTTP Header.
The form requires 'Post' submissions, which adds a little more complexity.
Alternative
The other thing I've considered is to store the values in a cookie right before submission, which I can retrieve on the next page and then submit another Post; however I'd like to refrain from exposing the data in Cookies.
AFAIK, Javascript does not have access to the POST body. Can't think of an API call for that! If you are using php/.net/ruby, you can encode the POST body as JSON that your JS can use when it's reloaded, can't you?