ricmetal Posted July 2, 2010 Share Posted July 2, 2010 hey anyone tell me why the xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); dec doesn't work. the ' character still get's a slash added before it and appears in the the database, as opposed to not appearing in the database when the ' char is submitted through a html form with enctype set to urlencode. is the reqeustheader supposed to emulate the html enctype or do i have to add more encoding and decoding? i didn't really want to have the info in the database appeared as characters other than normal readable text. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted July 2, 2010 Share Posted July 2, 2010 You're gonna have to list more code. But, just going off of what you said, you need to strip the slashes, then escape the data before inserting. Quote Link to comment Share on other sites More sharing options...
ricmetal Posted July 2, 2010 Author Share Posted July 2, 2010 hi f1fan thanks for replying the rest of the code is probably okay i saw a couple of examples on how to post using ajax and they all where very similar to my code. and the differences, i tried with no avail. i dont post the code bacause it's alot of it, and it's all interconnected between php's and js's, but the basics i think the point is is that that setHeaderRequest line should treat input field values like the form tag does. at least that's what is looks like it should do! i'll have a go at encoding and decoding, although i'll probably still look around for more explanations on this as i don't like writing code with encodes and decodes, specialy unsafe ones like stripslashes and similars. Quote Link to comment Share on other sites More sharing options...
ricmetal Posted July 2, 2010 Author Share Posted July 2, 2010 okay, i hate to go into encodings and decodings, and i need to buy a javascript book to learn more about js's inner workings but i got my problem solved, escaping and encoding. i tried jquery's ajaxform and bullshit, it didn't help with stripslashing and character encoding, so i managed to emulate the ajax form and improve it with just a few lines of js anyway for the peeps looking to have ajax forms and are stuck with encodings and characters here's a few thing to look up in order to get the job done. (thanks f1fan) i'll actually post the lines i changed in my code (note that i dont go into charsets, but i do have my main html files with charset set to utf-8. you might want to look into setting charset headers for php files used with ajax) just review and acomodate: <!-- encodeURIComponent --> var params = "textContent="+encodeURIComponent(textContent)+"&cacheid="+Math.random(); xmlHttp.open("POST", url, true); <!-- FUNCTION TO STRIP SLAHES I HAVE FROM A PHP GURU WHICH I HIRED SOME TIME BACK --> <?php function UndoMagicQuotesLambda(&$value, $key) { $value = stripslashes($value); } if (get_magic_quotes_gpc()) { $aMagicQuoted = Array( '_POST', '_GET','_COOKIE', '_REQUEST'); foreach ($aMagicQuoted as $var) array_walk_recursive($GLOBALS[$var], 'UndoMagicQuotesLambda'); } ?> <!-- AND ON THE PHP SCRIPT CALLED FROM THE XMLHTTP OBJECT --> include '../phpincludes/m_quotes.php';//WHICH CALLS THE ABOVE FUNCTIONS $textContent = $_POST['textContent']; regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.