2

I'm still new to WordPress. I have been encountering Failed to load resource: the server responded with a status of 404 (Not Found) error and its pointing it in wp-admin/admin-ajax.php. I have check the folder and admin-ajax.php is there. I also tried calling admin-ajax.php using network_admin_url() instead of admin_url(). But I still keeps on having that error. Is there anyway to solve it? Thank you very much for your help.

Here is the sample code

var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
  $.ajax({
    type: "POST",
    url: ajaxurl,
    cache: false,
    data: { action: 'getInfo' },
    success: function(data) {
      mIDs= mDisplay(data);
    }
  }).done(function( msg ) {

  });
3
  • Where is this JS being written? In a template? JS file? Functions file? Commented Feb 5, 2018 at 5:43
  • @JacobPeattie it is in my header.php, in a template
    – natsumiyu
    Commented Feb 5, 2018 at 5:50
  • Please check on page source , if there is perfect url as you want Commented Feb 5, 2018 at 9:43

4 Answers 4

2

I contact the hosting provider regarding it. They advise me to fix the .htaccess which causing the error.

1
  • 1
    Hi @natsumiyu How did you solve this, please?
    – Daydah
    Commented May 5, 2019 at 12:21
0

finally the problem was that the hosting provider had blocked the admin-ajax.php file saying that this file was receiving too many request, and requests to this file bypasses cache , hence it was causing problems on server :)

2
  • Thank you very much for your reply. How will I know if its the hosting provider fault?
    – natsumiyu
    Commented Feb 5, 2018 at 4:18
  • You'd need to ask. Commented Feb 5, 2018 at 5:43
0

I assume you're writing javascript with in php file.

var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; You're going to save the return value in ajaxurl variable, so you shouldn't echo it.

For external js files, you have to use wp_localize_script to pass ajaxurl to js file

0

Check if your host has ModSecurity enabled, disable it and give it a try.

worked for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.