Domanda

I have created an AJAX voter and it only seems to work on the root domain. So if I am looking at the homepage, mydomain.com, the voting is fully functional on that page. If I am looking at something in mydomain.com/topic/article2.html it does not work. For some reason, the script can't seem to find the vote.php file even though I placed it in the root. The Ajax request gives status 500 (internal server error) and I would expect a 404 for file not found. I played with some different combinations of the reference location, such as "./vote.php" and "vote.php" and the problem doesn't change. I also tried placing the vote.php file in other locations, but none of the places I tried panned out. Any help would be greatly appreciated because I have spent hours on this reading through possible solutions online but can't find a solution.

I am using the script in Joomla 2.5 and Seblod 3.1, if that helps.

Nothing crazy going on in my script, but I think it has something to do with "./vote.php" perhaps there is a way to force the server to check the root from other locations.

<script>
function SetVote(vote_choice, a, u)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    //  document.write(xmlhttp.responseText);
    document.getElementById("result"+a).innerHTML=xmlhttp.responseText;
    }
  }    
xmlhttp.open("GET","./vote.php?vote="+ vote_choice + "&a=" + a + "&u=" + u,true);
xmlhttp.send();
}
</script>
È stato utile?

Soluzione

In terms of pathing:

  • / means the root directory
  • ./ means the current directory
  • ../ means the directory above the current directory.

So, as long as you aren't working on the server-side, /vote.php should fix the problem.

Altri suggerimenti

The command "./" will only move you down 1 by one subdirectory (if you had a file in /php/submit "./" would reference "/php" not "/".) Try replacing "./vote.php?" with "/vote.php."

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top