我有一张表格:
<form action="moods.php" method="post" id="geog">
Longitude: <input size="15" id="lonbox" name="lon" type="text" />
Latitude: <input size="15" id="latbox" name="lat" type="text" />
<input type="submit" />
</form>
我希望使用上面的单个表单同时将mooditude经度的值提交给除了moods.php之外的多个.php文件。
我该怎么做?请提出一些建议..
答案 0 :(得分:1)
您可以将其提交到包含可处理多个提交的cURL脚本的文件
<form action="multi_submit.php" method="post" id="geog">
multi_submit.php上的使用cURL
处理表单提交答案 1 :(得分:1)
为什么表单提交到多个页面,当你可以有一个单独的脚本include()其他脚本?
require('script1.php');
require('script2.php');
require('script3.php');
答案 2 :(得分:0)
如果你真的需要在多个.php文件中提交值,并且dqhendricks提供的require选项无法解决,为什么不使用多个Ajax调用?每个文件一个。
你可以这样:
<form onsubmit='sendSeveralPost()'>
... form fields
</form>
和javascript函数
function sendSeveralPost() {
var f1 = document.getElementById('field1');
var f2 = document.getElementById('field2');
var x = getXmlHttp();
var params = 'field1='+f1+'&field2='+f2;
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
x.setRequestHeader("Content-length", params.length);
x.setRequestHeader("Connection", "close");
var files = new Array();
files[0] = 'script1.php';
files[1] = 'script2.php';
files[2] = 'script3.php';
for (i=0;i<files.lenght;i++) {
var url = files[i];
x.open("POST", url, true);
x.onreadystatechange = function() {//Call a function when the state changes.
if(x.readyState == 4 && x.status == 200) {
alert(x.responseText);
}
}
x.send(params);
}
}
function getXmlHttp() {
var xmlHttp;
try { // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
try { // Internet Explorer 6.0+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try { // Internet Explorer 5.5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
关于这些命令的进一步解释可以在文章http://www.openjs.com/articles/ajax_xmlhttp_using_post.php中找到,我从这里获得了这个例子的灵感。
希望这有帮助。
NAMASTE!