AJAX请求不发送阿拉伯字符 [英] AJAX Request Not Sending Arabic characters

查看:163
本文介绍了AJAX请求不发送阿拉伯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了jQuery的post发送请求到服务器,以获得客户的名字开始的请求,但问题是它只发送英文字符
这是邮政编码

I wrote jQuery post to send request to the server to get customers that their names begins with that request but the problem is it sends only english characters Here is the post code

console.log("1 - "+inputString); //return Arabic right
console.log("2 - "+decodeURIComponent(inputString)); //return arabic right
console.log("3 - "+encodeURIComponent(inputString)); //encoded Arabic 
inputString = decodeURIComponent(inputString); 
console.log(inputString); //also arabic right
$.post("<?= base_url(); ?>admin/customers/get_customer/"+inputString, function(data){
                alert(data); 
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });

在服务器端

function get_customer($customer)
    {
        header ('Content-type: text/html; charset=utf-8');
        die($customer." - - ".utf8_decode($customer)." - - ".utf8_encode($customer)); //just for testing and all returns encoded characters 

        $query = mysql_query("SELECT * FROM customers WHERE customer_name LIKE '$customer%' LIMIT 10") or die(mysql_error());
        $str = ""; 
        while ($result = mysql_fetch_object($query) ):
            $str .= '<li onClick="fill(\''.$result->customer_id.'\',\''.$result->customer_name.'\');">'.$result->customer_name.' </li>';
        endwhile;
        echo $str; 

    }

视图文件中的字符集是utf-8 HTML& PHP
此外,jquery的字符集是UTF-8
所以有什么问题

The character set in the view file is utf-8 by HTML & PHP Also The charset of the jquery is UTF-8 So what is the problem

推荐答案

已解决这是我的解决方案

I have solved it this is my solution

function get_customer($customer)
    {
        header ('Content-type: text/html; charset=utf-8');
        $customer = urldecode($customer);//this is the solution decode the url 
        $query = mysql_query("SELECT * FROM customers WHERE customer_name LIKE '$customer%' LIMIT 10") or die(mysql_error());
        $str = ""; 
        while ($result = mysql_fetch_object($query) ):
            $str .= '<li onClick="fill(\''.$result->customer_id.'\',\''.$result->customer_name.'\');">'.$result->customer_name.' </li>';
        endwhile;
        echo $str; 

    }

这篇关于AJAX请求不发送阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆