我有一个函数,它接受国家名称并通过 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/