jquery - 向 PayPal 购物车发送文本会导致出现奇怪的字符

标签 jquery html string text paypal

我使用的是基本的 PayPal 购物车(网站支付标准)。

我的 HTML 中有以下内容作为项目描述的一部分:

<div class="block">
    <p>What&rsquo;s yours?</p>
    <!-- some other html -->
</div>

然后我像这样选择这段文字:

phrase = $('.block p:first').text();

我也试过这个:

phrase = $('.block p:first').html();

然后,在提交之前,我将其复制到这样的表单中:

$('#PayPalForm input[name=os1]').val(phrase);

表单如下所示:

<form id="PayPalForm" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart" />
    <input type="hidden" name="business" value="redacted" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="add" value="1" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="return" value="paypal_confirm.html" />
    <input type="hidden" name="cancel_return" value="redacted" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="bn" value="PP-ShopCartBF" />
    <input type="hidden" name="item_name" value="" />
    <input type="hidden" name="on1" value="phrase" />
    <input type="hidden" name="os1" id="os1" value="" />
</form>

这是我的 HTML 文档类型:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

这是我的文本编码:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

它正在工作。但是,当远程托管的购物车页面打开时(在 PayPal),该短语会在应该是撇号的位置显示无意义的字符。

phrase: What’s yours?

至少我希望显示原始 而不是 '

为什么会发生这种情况,我可以做些什么来清理它?

最佳答案

您应该能够指定表单中包含的信息的编码:Setting the Character Set – charset .

<input type="hidden" name="charset" value="utf-8">

关于jquery - 向 PayPal 购物车发送文本会导致出现奇怪的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8481334/

相关文章:

javascript - 未捕获的类型错误 : Cannot read property 'setAttribute' of null

jquery - 使用 jquery ui-sortable 选择框在 Mozilla 16.0.1 中不起作用

javascript - 计算javascript中的总值没有给出正确的结果

python - 考虑删除获取接近的字符串匹配 - python

c - 当没有语法错误时,此代码中的 if 情况不起作用

javascript - 为什么 Colorbox 不适用于点击事件?

javascript - 父类的唯一标识元素

javascript - 如何用拆分 (_) 替换文本

javascript - HTML 不会在 Bootstrap Modal 中动态添加表单字段的值属性

java - 如何检查字符串是否有连续的空格