I have an ajax post, but it's getting cancelled. I just made a test.php
file which is just supposed to echo 'test';
value.
This is how my ajax script looks like:
function loadAd(date) {
var ajax_url = '<?=URL?>components/ajax/grab_ads.php';
$.ajax({
type: 'POST',
url: ajax_url,
dataType: 'html',
data: ({
date : date
}),
cache: false,
success: function(data) {
if(data > 0) {
$('.advert').fadeIn("fast");
}
},
error: function(xhr, textStatus, errorThrown) {
//alert('Nastala chyba. ' + errorThrown);
}
});
}
The function is called, I tried console logging it. The variable is passed okay as well. This is what I'm getting in chrome network tab. screenshot
Other than that I am quite helpless.
Edit: I call the function like this:
$datum = Date("d-m-Y H:i:s");
$adl .= '<script type="text/javascript">
loadAd(\''.$datum.'\');
</script>';
we were making the ajax request from a link, and not preventing the link from being followed. So if you are doing this in an onclick attribute, make sure to return false; as well
function loadAd(date) {
var ajax_url = '<?=URL?>components/ajax/grab_ads.php';
$.ajax({
type: 'POST',
url: ajax_url,
dataType: 'html',
data: ({
date : date
}),
cache: false,
success: function(data) {
if(data > 0) {
$('.advert').fadeIn("fast");
}
},
error: function(xhr, textStatus, errorThrown) {
//alert('Nastala chyba. ' + errorThrown);
}
});
return false;
}
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