M
M
mmka2014-01-31 01:27:27
PHP
mmka, 2014-01-31 01:27:27

Why does an Ajax GET request containing Cyrillic characters return crocodile characters?

It returns crocozyabras to me кухни, after php function rawurlencode %D0%BA%D1%83%D1%85%D0%BD%D0%B8. The utf8 encoding without the boom in htacces by default is also written on the page. Is it possible to somehow convert it back to Cyrillic? The data is taken from the input using the jquery method, here is the code:

<div><input id="p_38" class="checkbox pourpo" type="radio" name="parameters" value="Для ванной"><label for="p_38">Для ванной</label></div>


$('.pourpo').click(function(){
    var template = $("#usageList").html();
    var inppourpo = $(this).val();

      $.ajax({
        type: 'get',
        url: '/filter/pourpose/'+inppourpo,
        dataType: 'json',
        contentType: 'application/json',
        success: function(data) {
            $(".prodlist").html(_.template(template,{inppourpo:inppourpo }));
        }
      });

  });

Answer the question

In order to leave comments, you need to log in

7 answer(s)
R
romansamko, 2014-01-31
@romansamko

This often happens when the web server (apache, nginx, etc) does not specify an encoding

A
akashtrih, 2014-01-31
@akashtrih

Try to form the url parameter like this:
And on the server side, to get the original string, use urldecode ().
By the way, the parameter contentTypetells the server what data was passed to it by the ajax request. In this case, no data in the parameter datais transmitted to the server, I don’t see the point of specifying contentType ( details ).

M
Max, 2014-02-01
@zenwalker

Your kryakozyabry is an attempt to read UTF-8 as WINDOWS-1251. Are you sure the display encoding is UTF-8?
Just because an encoding is set in .htaccess doesn't mean it can't be overridden elsewhere. Look in the browser debugger and check for the necessary headers, or try hard-coding the data encoding before uploading.
header("Content-Type: text/html; charset=utf-8");

E
Evgeny Fedorov, 2014-01-31
@JekFdrv

Or the required encoding is not specified in the ajax request, or when displayed in meta tags. Once upon a time, I suffered for a long time.

P
Petrusha Ukropov, 2014-01-31
@artishok

iconv

R
Rainbird, 2014-01-31
@Rainberd

Is the script file saved in utf-8?

S
Sergey Kravchenko, 2014-01-31
@GrandJaget

show what an ajax request returns

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question