Javascript 将文本参数传递给jQuery上的url变量at.load函数
我试图通过参数(带空格)将文本传递给load函数,但它似乎不起作用 目前我正在这样做:Javascript 将文本参数传递给jQuery上的url变量at.load函数,javascript,jquery,text,parameters,load,Javascript,Jquery,Text,Parameters,Load,我试图通过参数(带空格)将文本传递给load函数,但它似乎不起作用 目前我正在这样做: var text ="hello world this is an example"; $("#selector").load("http://"+ document.domain + "/myfunction/"+text); 有什么办法吗 如果我直接通过URL调用函数,而不是使用jQuery,那么它工作得很好 谢谢。您应该使用encodeURI对“文本”进行编码: var text = encodeUR
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');
这将确保您的空白被替换为与url兼容的字符,当您直接访问url时,浏览器会在内部执行此操作。您应该使用encodeURI对“文本”进行编码:
var text = encodeURI('hello world this is an example');
这将确保您的空白被替换为与url兼容的字符,当您直接访问url时,浏览器会在内部执行此操作。直接通过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 example
通过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 example