Ajax无法从应用程序的根文件夹访问目录UP中的文件

Im using this ajax call:

<script>

jQuery(document).ready(function(){
  jQuery('#compare_btn').click(function(event){
    event.preventDefault();
    var id=jQuery('#compare_btn').attr('name');
    alert(id);
    jQuery.ajax({
      type:"GET",
      data:{'propid':id},
      url: "compareAjax.php",
      success:function(result){
        alert(result);
      },
       error: function(req) {
                alert('Error: ' + req.status);
      }
    });
  });
});
</script>

The compareAjax.php contains only a

echo "working";

When i use for url : compareAjax.php and i place the file in the root folder of my site it is working as intended.

But when i move the file to: components/com_iproperty/views/compare/ and change url to "components/com_iproperty/views/compare/compareAjax.php" I get back a 500 Error from ajax request status.

Thinks i did :

  • From firebug i checked the Networking tab and the Request URL from call is correct.
  • I added both my file and folder to www-data group
  • Changed the permissions of both of em at 777

None of em worked. I moved file to components folder and changed the url of ajax also but again a 500 error pops.

Seems to be a server side issue but cant find out what. Does anyone have any idea what is going on ?

Change the url property as shown below.

url: "components/com_iproperty/views/compare/compareAjax.php",

try to use absolute path, sometimes helped for me:

url: "/components/com_iproperty/views/compare/compareAjax.php",