4

When I access the following url via browser it works fine returning JSON data,

http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php?p=33

When jquery does an ajax get it is failing with a 404 Not found error with the following code even when the file get.php truly exists on the server as mentioned above,

$.ajax( 
{
    url: "http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php",
    type: "GET",
    data: {p: postId}
})
.done(function(post) {
})
.fail(function() { alert("error"); })
.always(function() {  });

You may see the 404 error below, enter image description here

Currently the .htaccess has the following in it,

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Could this be causing the issue?

The same demo on the test server at, http://peplamb.com/workspace/azcentral.com/spotlight-stories/ works fine, but the same code is failing at http://azcvoices.com/topcompanies/spotlight-stories/

What could be the issue? Any help is greatly appreciated!

1 Answers1

6

Are you making the request from the same domain as the page is hosted on? If not, you might be running into a problem with Cross-Origin Resource Sharing.

To fix this, you might be able to add Access-Control-Allow-Origin: * as a header.

Matt Bryant
  • 4,841
  • 4
  • 31
  • 46
  • I don't think it took affect. I'm not seeing it in the headers when I fetch the page. EDIT- nevermind, appears to work now. – Matt Bryant Jul 10 '13 at 04:04
  • Hey Matt thanks for the quick response I added header("Access-Control-Allow-Origin: *"); to get.php file also went ahead and added AddType application/json .json to .htaccess file but still the same results any idea why? –  Jul 10 '13 at 04:06
  • Now can you can see it in the header? –  Jul 10 '13 at 04:07
  • Yes I can, and I can fetch it using AJAX. – Matt Bryant Jul 10 '13 at 04:08
  • i can see the data coming but its a 404 status code if you notice here http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php?p=33 –  Jul 10 '13 at 04:14
  • It looks like you are setting a weird status code. It is a 404 status, but all of the data is coming through, so it seems to work fine. `x = new XMLHttpRequest(); x.open("GET", "http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php?p=33"); x.send(null);` does return the proper data. – Matt Bryant Jul 10 '13 at 04:15
  • I know it does return perfect data when we test locally. As I said earlier, the same demo on the test server at, http://peplamb.com/workspace/azcentral.com/spotlight-stories/ works fine, but the same code is failing at http://azcvoices.com/topcompanies/spotlight-stories/ –  Jul 10 '13 at 04:26
  • 2
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33173/discussion-between-matt-bryant-and-peplamb) – Matt Bryant Jul 10 '13 at 04:27
  • 8
    Thanks for the hint Matt! header('HTTP/1.1 200 OK', true, 200); made it work! –  Jul 10 '13 at 04:57
  • Awesome - for some reason my local code needed this too! – itsricky Mar 27 '14 at 10:28