javascript - jQuery load() 没有在 url 中传递完整的字符串

标签 javascript jquery

我有一个函数,它接受国家名称并通过 load() 函数将其传递到处理页面。

在下面的例子中,国家是“美属萨摩亚”

function loadRates(oArg) {
        var Destination = oArg.Destination.toString() || '';
        alert(Destination); // Alerts "American Samoa"
        var uniqueid = new Date().getTime();
        $('#divRates2').html('<img src="/images/ajax-loader.gif">').load('inc_rates_output.cfm?Destination=' + Destination + '&uniqueid=' + uniqueid);
    }

但是,处理页面 (inc_rates_output.cfm) 将目标 url 变量接收为“美国”,即没有“萨摩亚”。

任何想法表示赞赏。

最佳答案

在 url 中使用 'encodeURI(Destination)'

URL 规范(RFC 1738,94 年 12 月)带来了一个问题,因为它将 URL 中允许的字符的使用限制为 US-ASCII 字符集的有限子集:

...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL.

关于javascript - jQuery load() 没有在 url 中传递完整的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9811087/

相关文章:

javascript - 如何在我的页面中加载所有图像后运行 jQuery 代码?

javascript - 尝试使用 nsIPrefBranch 在 Firefox 扩展上存储数据会给出 NS_ERROR_UNEXPECTED

javascript - 单击时从列表中获取值

javascript - 无法读取未定义的属性 'replace'

javascript - 向数组添加多个输入字段的问题

javascript - 简单的 chrome 重定向扩展

javascript - 当我单击图像进行评分时,另一张评分图像中也会发生同样的情况

Javascript内存管理和垃圾回收

jquery - 如何将随机类添加到链接列表

javascript - 淡入前 100% 完全显示图像