[英]Jquery Load and send variables to url
I use the function "load" of Jquery for load page , in this url i send by "load" some values as this example : 我使用Jquery的函数“ load”加载页面,在此url中,我通过“ load”发送了一些值,例如:
jQuery("#load_data").show(1000).load("index.php?send_values="+datasend+"");
The value "datasend" get these values from function javascript as this : 值“ datasend”从javascript函数中获取这些值,如下所示:
function getvalues()
{
var getdata="value 1";
getdata +="value 2";
getdata +="value 3";
var datasend=getdata;
}
If insert alert inside funtion i get all values , for example : 如果在功能中插入警报,我会得到所有值,例如:
function getvalues()
{
var getdata="value 1";
getdata +="value 2";
getdata +="value 3";
var datasend=getdata;
alert("Show"+datasend);
}
But if i use load of Jquery , this no works : 但是,如果我使用Jquery的负载,则此操作无效:
function getvalues()
{
var getdata="value 1";
getdata +="value 2";
getdata +="value 3";
var datasend=getdata;
jQuery("#loader").load("index.php?send_values="+datasend);
}
The other side in the page i want send/get values i have code in PHP , but when i do : 页面的另一边我想发送/获取值,我在PHP中有代码,但是当我这样做时:
<?php echo $_REQUEST['send_values'];?>
Only get the first data in this case "value 1" and no all values , but with javascript "alert" i get all values but load of jquery no send all values by URL for finally get all values 在这种情况下,仅获取第一个数据“ value 1”,而不是所有值 ,但是使用javascript“ alert”,我获取了所有值,但jquery的加载没有通过URL发送所有值,最终获取了所有值
Thank´s for the help , regards 感谢您的帮助,问候
If you check again, you will see that the data that arrives at the server isn't "value 1"
, but only "value"
. 如果再次检查,您将看到到达服务器的数据不是
"value 1"
,而仅仅是"value"
。
A correct URL can't contain spaces, so the load
method uses space as a separator between the URL and an optional selector to get a fragment from the loaded data. 正确的URL不能包含空格,因此
load
方法使用空格作为URL和可选选择器之间的分隔符,以从加载的数据中获取片段。 As there are spaces in the value in datasend
, only the part up to the first space is included in the URL, the rest is interpreted as a selector. 由于
datasend
的值中存在空格,因此datasend
中仅包含第一个空格之前的部分,其余部分解释为选择器。
You would use the encodeURIComponent
method to encode the value so that it can be used in the URL: 您将使用
encodeURIComponent
方法对值进行编码,以便可以在URL中使用它:
jQuery("#loader").load("index.php?send_values=" + encodeURIComponent(datasend));
Alternatively you can use the data parameter of the load
method to include the data: 另外,您可以使用
load
方法的data参数来包含数据:
jQuery("#loader").load("index.php", { send_values: datasend });
尝试做:
var datasend=encodeURIComponent(getdata);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.