我试图通过参数(带有空格)将文本传递给加载函数,但它似乎不起作用。
目前我正在这样做:
var text ="hello world this is an example";
$("#selector").load("http://"+ document.domain + "/myfunction/"+text);
有什么办法吗?
如果我直接通过 URL 调用该函数,而不是使用 jQuery,则效果很好。
谢谢。
最佳答案
您应该使用encodeURI对“文本”进行编码:
var text = encodeURI('hello world this is an example');
这将确保您的空格被替换为与网址兼容的字符,这是您直接访问网址时浏览器内部执行的操作。
关于javascript - 将文本参数传递给 jQuery 上 .load 函数的 url 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802618/