Good day. Using Ajax using the POST method, I send the value "+7 (913) 789-11-11"

$.ajax({ type: "post", url: "/aj.php", data: "name="+m_data, }).done(function( result ) { alert ('good'); }).fail(function(result) { alert ('bad'); }); 

But for some reason only 7 (913) 789-11-11 comes, i.e. the "+" symbol does not come. Please tell me how to solve this problem.

  • You rechecked that at the time of sending in data: m_data comes with a plus? - Sergiks

2 answers 2

It is necessary to process on the server as follows:

 urlencode($_POST['name']) 
  • There is no difference :) when sending by POST, the "+" sign does not come at all. - Maxim147
  • Those. you need to translate it into a symbol, and when received on the server, convert this symbol into a "+" sign - Maxim147
  • @ Maksim147, updated the post. - ModaL
  • Thank you "+" has come. But there was another problem - the symbol of parentheses: "+ 7% 28903% 29 + 930-11-11" - Maxim147
  • and in general all Cyrillic, here's the word "check" which became: "% D0% BF% D1% 80% D0% BE% D0% B2% D0% B5% D1% 80% D0% BA% D0% B0% 0A% 0A " - Maxim147

Found a solution, thanks "ModaL"

Java script:

  m_data = encodeURIComponent(m_data); 

PCP:

 $newStr = htmlentities($_POST['name']); 
  • @ Maksim147, I just wanted to say about encodeURI, but ahead of it;) - ModaL
  • I also thought about encodeURIComponent , but : jQuery, it seems, urlencode itself is the data passed to it in data: . Is not it so? - Sergiks
  • No, it does not - Maxim147