Access forbidden to file on xampp server

I realize this is not really a yii problem but has anyone come across this before? I’m using an ajax function to refresh a div every X seconds. I’m getting this error upon refresh of the div.

Access forbidden!

You don’t have permission to access the requested object. It is either read-protected or not readable by the server.

I should add, I’m running the xampp server as localhost and I’m using mac osx. The file in question, the updatedLoggedInList.php file, is in the same directory as the php file containing the ajax function below. I was originally getting a cannot find error but I changed the file path in the function and it now see’s the file, just can’t access it.

below is the ajax function




<script type="text/javascript">

    function ajaxFunction(){

	var ajaxRequest;  // The variable that makes Ajax possible!

	

	try{

		// Opera 8.0+, Firefox, Safari

		ajaxRequest = new XMLHttpRequest();

	} catch (e){

		// Internet Explorer Browsers

		try{

			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try{

				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){

				// Something went wrong

				alert("Your browser broke!");

				return false;

			}

		}

	}

	// Create a function that will receive data sent from the server

	ajaxRequest.onreadystatechange = function(){

                var list = document.getElementById('userList');

		if(ajaxRequest.readyState == 4){

			list.innerHTML = ajaxRequest.responseText;

		}

	}

	ajaxRequest.open("GET", "protected/views/room/updatedLoggedInList.php", true);

	ajaxRequest.send(null);

        

       

}

</script>


<script type="text/javascript">

			setInterval(function() {ajaxFunction();}, 5000);

		</script>



Any ideas people?

The URL you are requesting is not valid. Try this




ajaxRequest.open("GET", "room/updatedLoggedInList", true);



Here updatedLoggedInList is action name

Thanks Vinay. I tried the controller/action url and now I’m getting an object not found error.

Try this:




<script type="text/javascript">

        ...

        ajaxRequest.open("GET", <?php echo Yii::app()->createUrl("<controller>/<action>"); ?>, true);

        ...

</script>



Replace <controller> with your controller name and <action> with your action name.

browser doesn’t like that syntax, getting an unexpected token error <

Is it in anyway possible that something in my php.ini or other type of config file might be restricting access to the url or the original file I was looking for?

First try the URL manually by typing on browser url to verify is the URL is valid or working properly or not!

Yes the URL is valid, what do you think would be next to try?

I’m trying your original suggestion, with a slight modification on the URL


 ajaxRequest.open("GET", "protected/controllers/room/openRoom", true); 

room is the controller ID, openRoom is the action

It see’s this, but again I’m getting the access forbidden error message

I think it might be because the URL being requested is inside the protected folder, and I guess I’m not allowed access anything in that folder from outside. Any way around that?

Hi. What was the code you typed in?

I used the exact line that Vinay suggested.


ajaxRequest.open("GET", <?php echo Yii::app()->createUrl("protected/controllers/room/openRoom"); ?>, true);

I’ve tried it with the <> brackets and without. Both give me uncaught syntax errors.

It’s not the same cause you use wrong “protected/controllers/…” path. It have to be just controller/action.

See CController->createUrl documentation for further details on the parameters.

Sorry kokomo, I should have mentioned that I’d already tried that. That was my first approach, and this is where I started getting the object not found error. Only after I’d appended the Url with /protected/controllers/ could it find the Url, but then as I’ve said, I got the 403 error. I really appreciate your input though, would be such a relief if I could get this resolved.

I think I may have cracked it!! Don’t all requests have to go thru index.php? I added index.php?=r to the Url and now the ajax function seems to be working. Not sure if that’s the best way to do it though, but for now it will have to do. Thanks a million for your input.