In my below code you can see '$_SERVER['REQUEST_URI']' 'ContactCreate.php' which are two actions I need my single form sent to. I'm not sure how I can get this too work.
Thank you all in advance
$(function() {
$("#myform").on("submit", function(e) {
e.preventDefault();
$.ajax({
url: '$_SERVER['REQUEST_URI']' 'ContactCreate.php',
type: 'POST',
data: $(this).serialize(),
beforeSend: function() {
$("#message").html("sending...");
},
success: function(data) {
$("#message").hide();
$("#response").html(data);
}
});
});
});
Just add it next to each other:
$(function() {
$("#myform").on("submit", function(e) {
e.preventDefault();
$.ajax({
url: '<?php echo $_SERVER['REQUEST_URI']; ?>' ,
type: 'POST',
data: $(this).serialize(),
beforeSend: function() {
$("#message").html("sending...");
},
success: function(data) {
$("#message").hide();
$("#response").html(data);
}
});
$.ajax({
url: 'ContactCreate.php',
type: 'POST',
data: $(this).serialize(),
beforeSend: function() {
$("#message").html("sending...");
},
success: function(data) {
$("#message").hide();
$("#response").html(data);
}
});
});
});
you must use JS analog of REQUEST_URI
var request_uri = location.pathname + location.search;
On your code -
$(function() {
$("#myform").on("submit", function(e) {
e.preventDefault();
$.ajax({
url: location.pathname + location.search+ 'ContactCreate.php',
type: 'POST',
data: $(this).serialize(),
beforeSend: function() {
$("#message").html("sending...");
},
success: function(data) {
$("#message").hide();
$("#response").html(data);
}
});
});
});
</div>
You'll need 2 ajax calls. You can wait both to finish using $.when
method and execute common logic in there
$(function() {
$("#myform").on("submit", function(e) {
e.preventDefault();
$("#message").html("sending...");
var formSerialized = $(this).serialize();
var ajaxCall1 = $.post('$_SERVER['REQUEST_URI']', formSerialized);
var ajaxCall2 = $.post('ContactCreate.php', formSerialized);
$.when( ajaxCall1, ajaxCall2).done(function (v1, v2) {
$("#message").hide();
// your logic when both ajax request finished
});
});
});
It's also uncertain if $_SERVER['REQUEST_URI']
will resolve to anything on Javascript, it will depends on where this code is placed.