Post Form To More Urls
Solution 1:
You need a form with the action "1.php" and jQuery.
$('#form_id').submit(function(event){
event.preventDefault();
var $th = $(this);
$.ajax({
type: 'post',
url: '2.php', // note: edited by Ryandata: $th.serialize(),
success: function(){
$th.submit();
}
});
});
Solution 2:
Using JavaScript, yes
You'll want to make one call using the XMLHttpRequest function available in JavaScript to make an AJAX call to the php.2 script. The second call can then be done using document.forms["FORMNAME"].submit()
.
Libraries like jQuery's Ajax functions make it easier to use the XMLHttpRequest function. See the jquery.get(), jquery.post(), and jquery.ajax() (a.k.a $.get(), $.post() and $.ajax()) function documentation
Here are a few guides to doing AJAX calls using jQuery's $.post() and $.ajax() functions.
- (http://www.sitepoint.com/ajax-jquery-3/)
- (http://www.devirtuoso.com/2009/07/beginners-guide-to-using-ajax-with-jquery/)
- (http://www.phpfreaks.com/forums/index.php?topic=256503.0)
- (http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/)
Also here is an example framework of how this can be coded up:
<form id="exampleform" name="exampleform" action="1.php"> ... </form> <script type="text/javascript"> function submitForm() { ... // set up vars for $.post() call // Make the post call for the 2.php $.post( ... ); // Submit the form for 1.php document.forms["exampleform"].submit(); } </script>
Solution 3:
All above solution should work, but remember ajax is only alowed in same domain posting. This mean you are on http://example.com, you can only post to example.com/etc or sub.example.com If you really want to cross domain posting, you should create an empty ifram as target (id="iframeid") then change the target of the form to it:
<formtarget="_iframeid"action=""/>
After that you can use javascript to post to one page, and then change action url and repost again
Solution 4:
the quick and dirty way to do this is to post the form to one script which will in turn post it to a second script.
Post a Comment for "Post Form To More Urls"