Klian
Klian

Reputation: 1565

jQuery ajax call and a 404 error

Im trying to make a jquery ajax call but im getting a 404 error.

This is my code

jQuery.ajax({
    type: "POST",
    url: "/wp-content/themes/mytheme/ajax_functions.php",
    data: "sec=load_team&year=2010",
    success: function(msg){
        jQuery("#update_div").html(msg);
    },
    error: function(msg){
        console.log(msg.statusText);
    }
});

The website is not visible for everyone, Ive changed my hosts file:

xx.xx.xx.xx www.mydomain.com

Chrome inspector says:

POST http://www.mydomain.com/wp-content/themes/mytheme/ajax_functions.php 404 (Not Found)

But If I copy/paste that URL in the address bar, it exists...

Upvotes: 0

Views: 6198

Answers (3)

Klian
Klian

Reputation: 1565

In ajax_functions.php I had:

require('../../../wp-blog-header.php');

I changed it by:

require('../../../wp-load.php');

Now its working fine, but i dont know why doesnt work with wp-blog-header because its in the same folder as wp-load.php

Upvotes: 4

Terry
Terry

Reputation: 14219

Is the ajax_functions.php page on the same domain as the page hosting the Javascript?

You may be getting blocked because of XSS in which case you'll need to specify a dataType of jsonp in your AJAX options.

Otherwise make sure the URL actually handles POST requests. If you need help with this, show your PHP code for that page.

Upvotes: 0

Kory Hodgson
Kory Hodgson

Reputation: 790

Try putting the full url "http://www.mydomain.com/wp-content/themes/mytheme/ajax_functions.php " in the url: parameter instead of relying on the module/browser to determine the domain.

Upvotes: 0

Related Questions