Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
AJAX: PHP $_POST Params Not Received

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
Jesdisciple
Frequent Poster
Frequent Poster


Joined: 20 Oct 2007
Posts: 36
Location: Tejas

PostPosted: Sun Oct 21, 2007 5:45 pm    Post subject: AJAX: PHP $_POST Params Not Received Reply with quote

I'm trying to get AJAX to work between my browser and localhost with the pretense that I need to keep some logic (i.e., for a bank script) confidential in a single-page app. Somewhere between
Code:
xmlHttp.open('POST', url, true);
...
xmlHttp.setRequestHeader("Content-Length", query.length);
xmlHttp.send(query);
and
Code:
<?php
   print_r($_REQUEST);
   ...
?>
my parameters disappear. Firefox, Opera, Internet Explorer, and JSLint have no complaints (except JSLint's nitpicking with the duplicate 'catch(e)'s). Here's the full code:

ClosedScript.html:
Code:
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>Untitled Document</title>
      &lt;script src="ClosedScript.js"></script>
      &lt;script type="text/javascript">
         function main(){
            var conf = new ClosedScript('ClosedScript.php');
            conf.request('content=event&q=load', listen);
         }
         function listen(response){
alert(response);
            if(response.indexOf('eval:') === 0){
               eval(response.substring(5));
            }
         }
      </script>
   </head>
   <body onLoad="main();">
      
   </body>
</html>


ClosedScript.js:
Code:
function getXmlHttpObject(){
   var xmlHttp;
   try{
      // Firefox, Opera 8.0+, Safari
      xmlHttp = new XMLHttpRequest();
   }catch (e){
      // Internet Explorer
      try{
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      }catch (e){
         try{
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
         }catch(e){
            alert("Your browser does not support AJAX!");
            xmlHttp = null;
         }
      }
   }
   return xmlHttp;
}

function ClosedScript(url){
   var _this = this;
   var xmlHttp = getXmlHttpObject();
   xmlHttp.onreadystatechange = function(ev){
      switch(xmlHttp.readyState){
         case 0:
            
            break;
         case 1:
            
            break;
         case 2:
            
            break;
         case 3:
            
            break;
         case 4:
            _this.respond(xmlHttp.responseText);
            break;
      }
   };
   xmlHttp.open('POST', url, true);
   
   this.request = function(query, responseFunc){
      if(typeof(responseFunc) == 'function' && responseFunc.length == 1){
         xmlHttp.setRequestHeader("Content-Length", query.length);
         xmlHttp.send(query);
         this.respond = responseFunc;
      }else{
         throw 'IllegalArgumentException: \'responseFunc\' in \'request(query, responseFunc)\' must be a function which takes exactly one argument.';
      }
   };
}
ClosedScript.prototype = {
   constructor: ClosedScript,
   
   respond: null
};


ClosedScript.php:
Code:
<?php
   print_r($_REQUEST);
   if(isset($_POST['content'])){
      switch($_POST['content']){
         case 'event':
            if(isset($_POST['q'])){
               switch($_POST['q']){
                  case 'load':
                     echo "eval:alert('onload detected at localhost')";
                     break;
               }
            }
            break;
      }
   }
?>


Any observations?
_________________
In ALL things, strive for ><>,
Chris
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Jesdisciple
Frequent Poster
Frequent Poster


Joined: 20 Oct 2007
Posts: 36
Location: Tejas

PostPosted: Tue Oct 23, 2007 8:35 pm    Post subject: Reply with quote

This problem was fixed by adding this header:
Code:
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
just before the following lines:
Code:
xmlHttp.setRequestHeader("Content-Length", query.length);
xmlHttp.send(query);

_________________
In ALL things, strive for ><>,
Chris
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert