Ajax message gets canceled

I have an ajax message, but it is canceled. I just created a test.php file that should have the value echo 'test'; .

This is what 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 to start it. The variable is also transmitted well. This is what I get on the chrome network tab. screenshot

In addition, I am completely helpless.

Edit: I call the function as follows:

 $datum = Date("dmY H:i:s"); $adl .= '<script type="text/javascript"> loadAd(\''.$datum.'\'); </script>'; 
+4
source share
1 answer

We made an ajax request from a link and did not prevent the link from being respected Therefore, if you do this in the onclick attribute, be sure to return false; and

  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; } 
+6
source

Source: https://habr.com/ru/post/1481149/


All Articles