PHP POST数据用ASCII而不是UTF8

时间:2013-09-25 11:37:28

标签: php jquery ajax utf-8

通过POST从表单发送数据后,我遇到了编码问题。

当我使用像ą,ć,ę,ł,ñ等特殊的抛光字符时,我会得到什么?而不是正确的性格。我已经在第三天挣扎了,找不到问题。

网站使用的是UTF8,所有文件都是UTF8。表单使用AJAX发送数据并使用输出缓冲区(ob)获取响应。当我在Chrome中检查标题时,一切正常。所以看起来jQuery / Ajax / ob会发生什么事情?

我用于jQuery / Ajax / ob的所有函数:

的jQuery

function ajaxForm(oform,ni,wt,nhi) {
    if (wt==''||wt==undefined) {
        if (oform.id=='theLongForm') {
            // time out based on the form id
            wt=120000;
        } else if (document.forms[oform.id].timeout) {
            // use the specific time out setting
            wt=document.forms[oform.id].timeout.value;
        } else {
            // default time out setting
            wt=10000;
        }
    }
    if (ni==''||ni==undefined) ni=false;
    if (nhi==''||nhi==undefined) nhi=false;
    if (ni!=true) showIndicator();
    $('#'+oform.id).ajaxSubmit({
        url: oform.action,
        type: 'POST',
        dataType: 'xml',
        timeout: wt,
        error: function(){
            document.forms[oform.id].ajax.value='x';
            $('#'+oform.id).submit();

        },
        success: function(xml){
            if (processResult(xml)) {
                if (nhi!=true) $("#indicator").hide(200);
            }
        }
    });
    return false
}

PHP:

function outputAjaxHeader() {
    global $ajaxRequest,$doneAjaxHeader;
    if ($ajaxRequest && !$doneAjaxHeader) {
        // output ajax XML header
        header('Content-type: text/xml; charset: utf-8');
        print '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        print '<items>' . "\n";
        $doneAjaxHeader = true;
    }
}

function outputAjaxItemStart($elem,$option='general',$full=false) {
    global $ajaxRequest;
    if ($ajaxRequest) {
        print "\t" . '<item>' . "\n";
        print "\t\t" . '<name>'.($full?'':'#').$elem.'</name>' . "\n";
        print "\t\t" . '<option>'.$option.'</option>' . "\n";
        print "\t\t" . '<data><![CDATA[';
        ob_start();
    }
}

function outputAjaxItemEnd() {
    global $ajaxRequest;
    if ($ajaxRequest) {
        $buffer = ob_get_contents();
        ob_end_clean();
        print $buffer;
        print ']]>' . '</data>' . "\n";
        print "\t" . '</item>' . "\n";
    }
}

0 个答案:

没有答案
相关问题