Jump to content

Recommended Posts

The php file is merely

 

<?php 

echo('Test');

?>

 

The Ajax Call is

<script type="text/javascript">

function getHTTPObject(){   

if (window.ActiveXObject)

	return new ActiveXObject("Microsoft.XMLHTTP");   

else if (window.XMLHttpRequest)   

	return new XMLHttpRequest(); 

else { 

	alert("Your browser does not support AJAX.");      
	return null;  

	}
}


var HttpRequestObject = false;

if(window.XMLHttpRequest) {

   HttpRequestObject = new XMLHttpRequest();
   
}
else if(window.ActiveXObject) {

   HttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
   
}



function getProgress() {
  
  if(HttpRequestObject) {
  
      HttpRequestObject.open('GET', 'http://www.mysite.com/phpfile.php', true);
      HttpRequestObject.onreadystatechange = function() {
         if(HttpRequestObject.readyState == 4 && HttpRequestObject.status == 200) {
	    var progress = HttpRequestObject.responseText;
		alert(progress);
           }
      }
      HttpRequestObject.send(null);
}
}


</script>

 

 

It works fine if it is run on my server, but if I try to access it from another domain, it does not work.

Link to comment
https://forums.phpfreaks.com/topic/178260-php-ajax-call/#findComment-939901
Share on other sites

It depends what you are wanting to do, but I know that you can send an AJAX request in the JSONP format using jQuery, which lets you load data from another domain using a callback.

 

The reason why what you are doing is dangerous is because I can create files, delete files, modify files, mess around with your database, and a whole host of other things that PHP offers on your server, especially with exec() and related functions.  This is why most people frown on eval.  It does have its uses, but in most cases if you have to use eval you are doing something wrong.

 

Edit: I realized I may be mis-understanding what you are trying to do, so all this could be moot.

Link to comment
https://forums.phpfreaks.com/topic/178260-php-ajax-call/#findComment-939917
Share on other sites

It depends what you are wanting to do, but I know that you can send an AJAX request in the JSONP format using jQuery, which lets you load data from another domain using a callback.

 

The reason why what you are doing is dangerous is because I can create files, delete files, modify files, mess around with your database, and a whole host of other things that PHP offers on your server, especially with exec() and related functions.  This is why most people frown on eval.  It does have its uses, but in most cases if you have to use eval you are doing something wrong.

 

He's not having them run code, he's having them call a php script on his server from an ajax function on their site. Nothing dangerous with that. Well, no more so than usual.  He still needs to sanitize user input, as usual, but aside from that, I don't see any security vulnerability.

Link to comment
https://forums.phpfreaks.com/topic/178260-php-ajax-call/#findComment-939921
Share on other sites

This is turning more into a JavaScript question.  I don't think you have to use JSON now that I look at it.  Check out the jQuery .ajax() docs.

 

There are not really any permissions you can set for any files, because the same origin policy is implemented at the browser-level.

Link to comment
https://forums.phpfreaks.com/topic/178260-php-ajax-call/#findComment-939943
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.