Jump to content

HTML encoding/decoding issues


germs12

Recommended Posts

I am having an interesting error in my AJAX app...

I am trying to take the contents of a rich text editor and send it to the server using an XMLHttpRequest via GET and save it to my MySQL database, then be able to retrieve it again and load it into my rich text editor.  The problem is that my encoding and decoding is really messing my style tags up and I am losing all styles.

Has anyone else experienced anything like this before? Does anyone know the correct encode/decode function to use?  I am using Javascript on the client and PHP on the server.  Any help would be great.

Thanks.
Link to comment
Share on other sites

OK....

I take some html tags and in JS do encodeURIComponent.  I then send it over to my PHP server, urlencode it  and send it back and do a decodeURIComponent.  I am losing half my html.

Here is what I start with.

<textarea cols="50" rows="10" id="normal_text" name="normal_text"></textarea><br>
<textarea cols="50" rows="10" id="encoded" name="encoded"></textarea><br>
<textarea cols="50" rows="10" id="rpc_response" name="rpc_response"></textarea><br>

This is what it encoded to.
%3Ctextarea%20cols%3D%2250%22%20rows%3D%2210%22%20id%3D%22normal_text%22%20name%3D%22normal_text%22%3E%3C%2Ftextarea%3E%3Cbr%3E%0A%09%3Ctextarea%20cols%3D%2250%22%20rows%3D%2210%22%20id%3D%22encoded%22%20name%3D%22encoded%22%3E%3C%2Ftextarea%3E%3Cbr%3E%0A%09%3Ctextarea%20cols%3D%2250%22%20rows%3D%2210%22%20id%3D%22rpc_response%22%20name%3D%22rpc_response%22%3E%3C%2Ftextarea%3E%3Cbr%3E

and this is what gets retuned.
<textarea+cols=\"50\"+rows=\"10\"+id=\"normal_text\"+name=\"normal_text\">


WTF?  I lose half of my html.  Any ideas?  I would show you the site, but it is inward facing on campus, sorry.
Link to comment
Share on other sites

Well, it would have helped if you showed us the JS code... but have you tried using POST instead of GET?  (I'm only assuming that's the method you're using).  You can pass more data in POST than GET and I think that may be the issue you're running into.
Link to comment
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.