我尝试通过参数(带有空格)将文本传递给load函数,但似乎不起作用。
目前我正在做这件事:
var text ="hello world this is an example";
$("#selector").load("http://"+ document.domain + "/myfunction/"+text);有什么办法可以做到吗?
如果我直接通过URL调用函数,而不是使用jQuery,它会工作得很好。
谢谢。
发布于 2012-10-09 22:49:54
你应该用encodeURI对“文本”进行编码:
var text = encodeURI('hello world this is an example');这将确保您的空白替换为兼容url的字符,当您直接访问url时,您的浏览器会在内部执行此操作。
发布于 2012-10-09 23:14:09
通过URL直接调用函数在您的浏览器中可能工作得很好。但这不是未来的证据。您必须使用encodeURI函数对您的url进行编码。在附加用户给定的数据之后。
var text ="hello world this is an example",
url = encodeURI("http://"+ document.domain + "/myfunction/"+ text);
$("#selector").load(url);在服务器端,您可以这样做,以取回用户输入的数据。
$data = urldecode($_SERVER['REQUEST_URI']);
// This will return
// /myfunction/hello world this is an examplehttps://stackoverflow.com/questions/12802618
复制相似问题