Why is jQuery ajax get returning a 404 Not found error even while the file exists on the server?

廉价感情. 提交于 2019-12-10 22:02:15

问题


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,

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:


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.



来源:https://stackoverflow.com/questions/17562122/why-is-jquery-ajax-get-returning-a-404-not-found-error-even-while-the-file-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!