duanhui9840 2014-06-04 22:23
浏览 44
已采纳

jQuery加载字符编码问题

Please note, I have read the similar questions and the suggested answer frequently popping up:

<?php
 header("Content-Type: text/html; charset=utf-8");
 ?>

Did not solve the issue.

Here's the header of my outer page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        ...

Here is a sample of inner.php

 <p>£</p>
 <p><?php echo $employee->salary; ?></p> <!-- employee->salary = £30,000 (from db) -->

I'm loading with jquery:

 $('#salary').load('inner.php')

On the output of the outer page I'm seeing:

£
�30,000

inner.php when viewed in the console looks like:

£
£30,000

I need the output on the outer page to appear as £30,000 and I'm unable to figure out what I'm doing wrong

  • 写回答

1条回答 默认 最新

  • dongyan3616 2014-06-04 22:37
    关注

    Play around with utf8_decode or utf8_encode and wrap it around your DB Output:

    <p><?php echo utf8_encode($employee->salary); ?></p>
    

    Maybe your DB isn't delivering UTF-8 strings.

    If you not have any reason to use the ISO-8859-1 charset on your site other than external text of which you have no control over (and is in fact encoded iso-8859-1), use UTF-8 in

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊