Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question passing special chars via GET using ajax

    I'm trying to create an editor to manage protect areas within Apache

    e.g

    Code:
    <directory "path/to/dir">
    ..relative settings..
    </directory>
    now I am successful at passing this data to my ajax handler and can verify it by using an alert.. however when I include this data in my xmlHttp.open string and it strips out all the open and close directory structures leaving just the innards

    Code:
    	  else
    	  {
    	  alert(data);
    	  xmlHttp.open("GET","/includes/process.inc.php?action="+page+"&data="+escape(data),true);
    	  xmlHttp.send(null);	  
    	  }
    does JS have a function to properly encode the data so it all remains intact?

    thanks
    IF I DID GOOD THROW ME A REP POINT

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    encodeURI or encodeURIComponent, depending upon your need.

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts
    doesnt seem to work... im still left with the missing <directory> tags
    IF I DID GOOD THROW ME A REP POINT

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    What does a data variable look like? The contents, that is.

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts
    an example of the data could be:

    Code:
     <Directory /usr/local/httpd/htdocs>
         Options Indexes FollowSymLinks
    </Directory>
    formatted with indentation in a textarea... There are many of these structures within the text area with numerous directives within them

    I've also noticed that any comment within the file (beginning with #) make the encodeURI stop working at that line
    IF I DID GOOD THROW ME A REP POINT

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Oh, Apache conf file. Ok.

    Have you tested echoing or dumping the contents on the backside file? What's going on back there?

    How odd. I don't know why it would break, but I've only used it on limited data. I'll play around a bit and see if I can figure something out. Hopefully someone who has seen this before will be able to help.

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I get all of the information on the backside in a little test setup I put together. Here's the code I used:
    Code:
    // test.php
    <html><head>
    <script type="text/javascript">
    function s()
    {
        // XmlHTTP setup courtesy of mjlorbet
        var XmlHTTP = null;
        var Possibles = {
            0: "XMLHttpRequest()",
            1: "ActiveXObject('Microsoft.XMLHttp')",
            2:"ActiveXObject('MSXML2.XMLHttp')",
            3:"ActiveXObject('MSXML2.XMLHttp.3.0')",
            4:"ActiveXObject('MSXML2.XMLHttp.4.0')",
            5:"ActiveXObject('MSXML2.XMLHttp.5.0')",
            6:"ActiveXObject('MSXML2.XMLHttp.6.0')",
            7:""};
        var Option = 0;
        while(XmlHTTP === null)
        {
            XmlHTTP = eval("new " + Possibles[Option]);
            Option++;
        }
        //return XmlHTTP;
    
        XmlHTTP.onreadystatechange = function()
        {
            if ( XmlHTTP.readyState == 4 )
            {
                document.getElementById("output").innerHTML = XmlHTTP.responseText;
            } // end: if
    
        }
    
        data = "<Directory /usr/local/httpd/htdocs>";
        data += "   Options Indexes FollowSymLinks";
        data += "</Directory>";
    
        url="backtest.php";
        url+="?id="+Math.random();
        url+="&data="+encodeURIComponent(data);
        XmlHTTP.open( "GET",url,true );
        XmlHTTP.send(null);
    }
    </script>
    </head>
    <body>
    <form action="" method="GET" onsubmit="s();return false;">
    <input type="submit" value="submit" />
    </form>
    
    <div id="output"></div>
    
    </body>
    </html>
    Code:
    // backtest.php
    <?php
    
    $data = $_GET['data'];
    
    if ( !($handle = fopen('testfile.txt','a') ) )
    {
        die(-1);
    }
    
    if ( fwrite($handle,$data."\n---\n\n---\n") === FALSE )
    {
        die(-2);
    }
    
    echo "end";
    
    ?>
    As can be seen, the backside gets exactly what I sent to it (ignoring the extra stuff I put in):
    Code:
    // testfile.txt
    <Directory /usr/local/httpd/htdocs>
        Options Indexes FollowSymLinks
    </Directory>
    
    ---
    
    ---


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •