我有一个带有用户名和密码的 HTML 表单。单击提交按钮后,我想在两个不同的服务器上发布两个不同的 PHP 方法。如何才能做到这一点?这可以使用 HTML 表单来完成吗?或者我应该使用 JavaScript 吗?有什么建议么?
更新
我尝试了以下代码,但它不起作用。我在这里错在哪里?先感谢您..!
<!DOCTYPE html><!--HTML5 doctype-->
<html>
<head>
<title id="login_form">Login Form testing</title>
<script type="text/javascript" src="//code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$('#loginform').submit(function(){
$("form" ).on( "submit", function( event ) {
event.preventDefault(); // prevent the default submission behavior
var data = $(this).serialize(); // gather data from the form and serialize it
$.post('URL_1', data, successAction1); // post it to destination 1
$.post('URL_2', data, successAction2); // post it to destination 2
});
var successAction1 = function() { alert("Success one");};
var successAction2 = function() { alert("Success two");};
});
</script>
</head>
<body>
<form id="loginform" action="">
<fieldset >
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName*:</label>
<input type='text' name='username' id='username' maxlength="50" />
<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
</body>