I have a form. This form will submit data to 2 different pages. After submit data to hidd.php I will redirect user to index.php. At the same time after submit data to hidd.php, data will be submitted to ns.php. I don’t want to wait for output from both page just quickly redirect user after submit data to hidd.php. So that was the question, how to redirect user without waiting for output after submit. Why I want to do this? It’s a long story, I even thought about using curl >> Send php variable to two pages
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
function submitForm() {
$.ajax({
type:'POST',
url: 'hidd.php',
data:$('#ContactForm').serialize(),
});
$.ajax({
type:'POST',
url: 'ns.php',
data:$('#ContactForm').serialize(),
});
return false;
}
</script>
</head>
<body>
<form id="ContactForm" onsubmit="return submitForm();">
Your subdomain: <input type="text" name="subdomain" value="" /><br />
Your ns1: <input type="text" name="ns1" value="" /><br />
Your ns2:<br /> <input type="text" name="ns2" value="" />
<br /><br />
<input type="submit" name="submit" value="Submit" /><br />
<div class="form_result"> </div>
</form>
</body>
</html>
You can use the $.post method. I’m not sure the structure of your php files but you can handle the posted data however you like.
html change from:
to:
the javascript:
changing the button from a submit to a button will stop the automatic redirect so you don’t have to return false. Then you are free to redirect when you want.