问题描述
我有一个表格.该表格会将数据提交到2个不同的页面.将数据提交到hidd.php
后,我会将用户重定向到index.php
.在将数据提交到hidd.php
之后,同时将数据提交到ns.php
.我不想等待两个页面的输出,只是在将数据提交到hidd.php
之后快速重定向用户.这就是问题,如何在提交后不等待输出的情况下重定向用户.为什么我要这样做?说来话长,我什至考虑过使用curl >> 将php变量发送到两页
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>
推荐答案
您可以使用$ .post方法.我不确定您的php文件的结构,但是您可以随心所欲地处理发布的数据.
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更改自:
<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>
收件人:
<form id="ContactForm">
Your subdomain: <input type="text" name="subdomain" value="" id="subDomain" /><br />
Your ns1: <input type="text" name="ns1" value="" id="ns1" /><br />
Your ns2:<br /> <input type="text" name="ns2" value="" id="ns2" />
<br /><br />
<input type="button" name="submit" value="Submit" id="submitButton" /><br />
<div class="form_result"> </div>
</form>
javascript:
the javascript:
$(document).ready(function(){
$('#submitButton').click(function(){
var subDomain = $('#subDomain').val();
var ns1 = $('#ns1').val();
var ns2 = $('#ns2').val();
$.post('hidd.php', {
subDomain : subDomain,
ns1 : ns1,
ns2 : ns2
});
$.post('ns.php', {
subDomain : subDomain,
ns1 : ns1,
ns2 : ns2
}, function(){
location.href="index.php";
});
});
});
将按钮从提交更改为按钮将停止自动重定向,因此您不必返回false.然后,您可以根据需要随意重定向.
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.
这篇关于提交到1页后,jQuery重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!