I have a little problem with jQuery ajax. I want to send a POST to a .php file and afterwards change the current URL. I tried the following code:
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
window.onload = function () {
$.ajax({
type: "POST",
url: "sample.php",
data: {'username': "STRING"},
timeout: 1000,
complete: function(){
window.location.href = 'http://127.0.0.1/sample/another.php';
}
});
}
</script>
So, as I can see in the chrome developer tools Network tab, no POST is executed. Although the URL changed to another.php
Can you tell me what I am doing wrong or how I can solve this issue?
use success instead of complete
$.ajax({
type: "POST",
url: "sample.php",
data: {'username': "STRING"},
timeout: 1000,
success : function(){
window.location.href = 'http://127.0.0.1/sample/another.php';
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With