Problem with posting via Ajax

Asked

Viewed 106 times

2

I’m creating a chat with websocket, when I send a message it saves the message in the database. This is the example of how it sends the message post inserir a descrição da imagem aqui

But the problem is when I send a function javascript (I’m trying to eliminate javascript injection in the input da mensagem). Follow the print of how it is sending (All buggy) and only save the beginning of the message:

inserir a descrição da imagem aqui

Could someone solve this problem for me? Follow the code in Jsfiddle of how I’m doing: http://jsfiddle.net/otww9e2k/ (see the requests sent via XHR to see the post getting bugged).

  • 2

    Take a look if this helps: http://jsfiddle.net/hympsp8f/

  • It didn’t work @Sergio

  • What is the error you have using my code? in devtools I see no error...

  • You know that right there in your image if you click on view source it displays exactly what you sent right?

  • Sergio , you should look at the XHR, for you see the post giving the same bug :/

  • @Ricardo and after the user select how this selected data can be sent to mysql. My case is as http://answall.com/questions/181981/form-din%C3%A2mico-e-send-to-mysql-via-jquery-e-ajax? noredirect=1#comment376494_181981

Show 1 more comment

1 answer

2


You can use encodeURIComponent javascript:

data: 'acao=' + encodeURIComponent(input),

When you receive the date on the server you should do a PHP Decode:

urldecode()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.