I have a html page with two iframes in them .there is a button on first iframe which should reload second iframe with some data which is sent on the click of the button ..but the first iframe containing the button should not reload.how can i make it possible ?
<?php
// code to send data without reloading page but instead reloading another iframe with sent data?>
In the first iframe, use javascript to submit the form by some sort of ajax method:
<form [...] onsubmit="sendAjax(); return false;">
The return false part prevents the form from submitting (as long as you don't have some sort of errors in your sendAjax() function.
Since it is going to take a bit of time for the server to process the request that should show up when iframe 2 refreshes, you could possibly use evilone's suggestion and use sessions to see if some sort of session variable has been set. Then in frame 2, make the javascript wait say 500 ms before refreshing and then refresh the page. You could loop this refreshing process to make sure that the session variable has been set and that the correct output will be sent.
Related
I'm using ajax to create list of replies.
In the end of the list I added textarea form that allow user to add reply (also with ajax).
The problem is that i call to my JS in my main PHP page so when user want to submit reply the page doesn't "know" the js code. If i add the js to the ajax php file/page the code will work but then it will be duplicated many times and when user will submit form the text will be submitted many times...
In my console i see that the JS file duplicate every time i load the replies list
How can i prevent it?
Disable the submit button right after user presses it once. Using jQuery:
$("#button").attr('disabled','disabled');
Make sure to remove disabled attribute on AJAX error so user can re-submit the form with new data. You can remove disabled attribute like this:
$('#button').removeAttr('disabled');
[improved]
if you want to not repeat data when navigation or F5 press, simply free the $_POST vars after doing whatever you want, and check if isnt set (before clean, of course) redirect you wherever you want. example:
/* HERE do the job with ajax response. */
if(!isset($_post['foo'])) header('Location: wherever.php');
$_POST['foo']=NULL;
If you're using $_GET... don't do it, use $_POST... $_POST is your friend.
Finaly ensure that if you press F5, you don't re-send form vars by post (otherwise you will get the same). If it's happening, clear your inputs with jQuery on page load.
$('#inputID').val('');
Is it possible to fill a form and Submit & Redirecting, but without refreshing the current page; without using jQuery or Ajax, in PHP.
I know how to do it by using jQuery, but the thing I was wondering is that why does the page refresh happens (on current page) and how to submit/redirect without the happening of the page refresh. In short everything happening in html/php
Quick answer No
PHP is a serverside language and therefor cannot be used to trigger client side events without using some form of javascript/jquery and websockets (or keep polling with ajax to the php script).
But what you can do is submit the form and redirect back to the current page. (The page will be refreshed)
I have the following problem: I have two pages. In the first page is a button. When the button is clicked, an ajax request is made to a page that saves data to the session. Then, it redirects me to the second page in which I display this saved data. The problem is that when I go to the second page the data is not displayed, but when I refresh the page the data is displayed. How can I redirect to the second page with the session data stored?
Example:
Before Refresh:
After:
Does anyone have any ideas?
You should wait for the response of the AJAX request before you forward to the next page.
Preferable use the callback method to redirect to the next page.
If you post some code may be it will be easier to point out.
Try this, hope it'll work
if you are using jQuery then fine, use e.preventDefault(); and redirect your next page after getting the ajax response.
I am wondering if it is possible to to resubmit a form with a button click that calls up a javascript command.
So this is basically what I'm trying to do -
page 1: form; action = page2.php
page 2: generate a randomized list according to parameters set by page 1
I would like to place a button on page 2 so that on click, it would be as if the user has hit F5, and a new list would be generated with the same parameters.
I found a lot of help on Google with people trying NOT to get this to happen, but I'm not sure how to actually get it to happen.....
Thank you!
You could use location.reload(true); to refresh the page.
<button onclick="location.reload(true);">refresh</button>
you only need to use. location.reload() instead of location.reload(true). since this will not disable caching for the reload but using true as the parameter will.
here is the reference. How to refresh a page in jquery?
EDIT: why not just use hidden input field and preserve the values and fetch it anytime you want to?
Is it possible to update the value of a variable from another page using JavaScript?
or
Is it possible to do this using form on submit, just update the other page, but remain on the page on which the form is located?
I think what you are searching for is AJAX (Asynchronous JavaScript and XML) which performs a get or post action and waiting for the result of the server. This makes it possible to submit a form without jumping to the page.
Have a look at this
Or if you use JQuery this
You can simply send all the data to be updated via Ajax and simply get the response on the current page You are in.