Hello. Since I send the form to the Ajax, I have to pass the data from the textarea through an escape (). The question is, is it possible to decode php into normal characters like php? Here is the send function.

$('#form').on('submit', function(e) { e.preventDefault(); var form = $('#form'); var formData = form.serialize(); var body = tinymce.editors['body'].getContent(); $.ajax({ url : form.attr("action"), type : form.attr("method"), data : formData + '&body=' + escape(body), dataType: 'json', cache: false, headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') }, error :function( errors ) { output = "<div class='alert alert-danger'><h4><i class='icon fa fa-ban'></i> Возникла ошибка</h4><ul>"; $.each(errors.responseJSON, function(index, error){ output += "<li>" + error + "</li>"; }); output += "</ul></div>"; $('#append').html(output); }, success: function(data){ output = "<div class='alert alert-success'><h4><i class='icon fa fa-check'></i> Готово</h4>"; output += data.success; output += "</div>"; $('#append').html(output); setTimeout(function(){ window.location.replace('{{ url('panel/article') }}')}, 3500 ); } }) }); 

    1 answer 1

    Honestly, I hear the escape first time. I usually use a similar (apparently) encodeURIComponent . I think the difference is small. Reverse server process - urldecode :

    http://php.net/manual/ru/function.urldecode.php

    PS

    Googled escape and read the description. I also recommend you: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/escape

    Switch, nevertheless, to encodeURIComponent .

    • I tried urlencode before entering in the database, nothing has changed. Now I will try with your function - Alex_01
    • @ Alex_01 urlencode - encodes a string. urldecode - decodes. With urlencode , for some reason, you have encoded an already encoded one. It turned out, I think, even worse) - Ivan Pshenitsyn
    • Thank you very much for your help) really, I messed up everything) now fixed) thanks again) - Alex_01