Is it possible to replicate f5 action to link using jquery? I need to refresh the page and resend data using this link, I have tried :
location.reload(true); or document.location.reload(); or $.f5();
But did not satisfy me.
Steps to reproduce using f5 key :
1. fill form then submit
2. press f5 - confirm box will appear
The page that you're looking for used information that you entered.
Returning to that page might cause any action you took to be repeated.
Do you want to continue?
try using
window.location.reload(true);
if it wont resubmit the form. you have two more options.
Submit the form using ajax after once submitted and resubmit the form and second time refresh the page or clear the form
Or you can keep the post data in some session or in the post array [server side code] and refill the form and resubmit,
Make sure you keep the track of numbers of submit you made since it will cause you trap in some recursion.
BUT why you want to resubmit the form you already have data you can perform both actions,
And if you have to post the form to some other action for second submit you can do the same may be using CURL at server side.
Try this:
window.location.reload(false);
// If we needed to pull the document from
// the web-server again (such as where the document contents
// change dynamically) we would pass the argument as 'true'.
source
Related
Basically my user inputs code. I can't check whether this code is valid or not(algorithm is a secret). Therefore I send(with form submit) this code to website that checks it (as $_POST variable). I have managed to do that. But how do I:
-Not display this webpage (user must stay on my webpage!)
-Get part of html from the website, that should not show and use it to fill variables (I know exactly which part of html I am looking for)
Can anyone point in the right direction with this problem..
jQuery has a simple function to add an event handler for submition and a function for posts, if you use the preventDefault function for the submit event, the form's action doesn't get performed, i.e. the side doesn't get reloaded. the html code you want to receive has to be fetched on server side, and transmitted back to the client
$('form').submit(function(e){
e.preventDefault();
$.post("example.com/somefile.php", sentData, function(receivedData){
useTheResponseData(receivedData);
});
});
I have a page, to which I POST information via form method="post". I would like to relaod it with JavaScript, but location.reload(true) and location.reload() makes browsers ask if I want to send the POST data again.
I would like to make JavaScript reload the page with GET instead of POST to skip the POST data.
How can I achieve that?
window.location.href = window.location.href
try
To reload a page without post data using javascript the easiest way I've found is to use an extra form to submit - this works regardless of whether the url is # or anything.
<form name="reloadForm">
<button type="submit">
Continue
</button>
</form>
<script>
document.reloadForm.submit() ;
</script>
That will show a button briefly on screen that the user can click continue on but the script will automatically submit it - this method sorts out a number of problems - the form is empty so it will not submit any post data (the button isn't named so even that won't submit a value). It works even if the url is set to #, and finally it gives a backup in case the user has disabled javascript (or the javascript doesn't work for some reason) they've still got a continue button available to click.
am using a form to register the user on my website and i have a captcha security on it. Everything is working well and good but the only problem that i am facing is that if i enter a wrong captcha or somehow the page refreshes , all the data entered by the user is wiped out.
what i wish to achieve is that even if the captcha entered is wrong and the form is submitted , the form should have all the fields intact as the user filled in excluding the captcha field.
How can this be done? My form is html and by using javascript im validating it
Some browsers may be smart enough to do this, but if you want to make sure, the only way to retain data across a page reload/refresh (including form submission) is to keep it on the server, and/or put it in a cookie.
However, instead of using a submit button, you could use a normal button with an onclick() function which validates the data first, then manually submits the form if appropriate.
document.forms["form_name"].submit()
You also have to handle key events for the form text inputs, to prevent enter from submitting.
However, this is still much easier in the end, since it prevents the page from changing and doesn't require server side storage or cookies.
I am writing a very heavy Javascript application using jQuery. One of the problems I am facing occurs when I perform AJAX form posts. Initially, the forms are rendered from a server side templating engine, these forms have default values set. The form has two options, SAVE and CANCEL (revert). When a user clicks "SAVE", the form data is POSTed to the server via jQuery. When the user clicks "CANCEL", Javascript's reset() function is called on the form.
The real problem occurs when I input/update fields on the form and then SAVE it. If I then attempt to edit the form again and click "CANCEL" the form is reverted back to it's original state (the state of the form on initial page render) and not that of the last AJAX submit.
It appears that Javascript's reset() function is using the 'value', 'checked', etc. attributes that were set on page render. If this is the case, what is the best way to update a forms values so that the reset() method will revert to the last point at which I submitted the form via AJAX?
you would need to "repaint" the forms so that their "initial values" are the ones that are on that AJAX submit. form reset rely on the value that came when the element is painted on the page. here's a demo to show the concept
just rebuild that form again, with a template and the successful values. you can do this on the fly using a JS template engine like mustache and maybe cache the template locally so you won't be doing extra HTTP requests
I'm using the document.form.submit() function for a rather large input form (hundreds of fields, it's an inventory application). I'm calling this after the user has been idle for a certain amount of time and I would like to save any data they've typed. When I try this the page reloads (the action is #) but any new text typed in the fields is not passed in the REQUEST, so I don't get to put it in the DB. Is there some fundamental reason why this happens or is my code just not playing nice together (I'm using the EXTJS grid view to show the form and a library for tracking idle time)?
Thanks,
Robert
I guess I put the answer here. What I found was that doing this:
setTimeout('frm.submit();', 2000);
caused the page to reload but didn't submit the form. When I did this:
frm.submit();
The form was submitted and the data was passed. I don't know why the first way didn't work, but I don't need to know that:)
Might the server be voiding out the input values. Say if your page on the server looks like this:
<form action="/page.cgi">
...
<input name="Fieldx" value=""/>
</form>
I think it'll void out the field. Or this the server action might be setting it indirectly. In JSF, something like this.
<input name="Fieldx" value="#{bean.nullProperty}"/>
What do you have on the server and what's your browser?
I would try to catch the HTML post request to see if the input fields are included. If they are then your server has problem.
But regarding what you said, I think it's because there's conflict in the way your browser handles JavaScript DOM. This may be the case if you leave out the submit button on your form and it works.
The submit method of HTMLFormElement objects should just submit the form, as if the user had clicked the submit button. So, if the action attribute of the form is set to #, it would just seem to refresh the page, because it’s sending the form data to the same page.
Strange that it still does it when you set the action attribute to another page though.
Is the method attribute of the form set to get or post?