I have an html form with 2 fields: name and email.
I need to submit the form values to 2 different urls from the same submit button. I have tried using jquery, serialize and post but I am not clear how to accomplish this. I cannot use PHP in this instance.
<!doctype>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<form action="" method="post" name="myform" id="myform">
<input type="text" value="name" />
<input type="email" value="email" />
<input type="button" id="submit" value="submit" />
</form>
<script type="text/javascript">
$(document).ready(function(){
var url1 = "some-url.com";
var url2 = "some-other-url";
$("#submit").click(function() {
$.post("url1", $("form#myform").serialize());
$.post("url2", $('formmy#myform').serialize());
})
})
</script>
</body>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…