[英]Ajax request delimiters for data to be sent
I have such an issue 我有这样的问题
var url = "index.php?id=123&sid=321";
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&url="+url,
success: function(msg){
alert( "Data Saved: " + msg );
}
Now here we have url which contains an & , but & is used to delimit data variables to be sent to server and so since we have this sign in url it thinks that this is a delimiter, and I am not getting the full url variable. 现在,这里有一个包含&的url,但是&用来分隔要发送到服务器的数据变量,因此,由于我们在url中具有此符号,因此它认为这是一个分隔符,而我没有得到完整的url变量。
Can somebody help with a wise solution. 有人可以提供明智的解决方案吗?
Thank in advance. 预先感谢。
Pass an object instead of string for the data
field: 为data
字段传递一个对象而不是字符串:
var url = "index.php?id=123&sid=321";
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", url: url },
success: function(msg){
alert( "Data Saved: " + msg );
}
});
var url = 'index.php?id=123&sid=321';
$.ajax({
type: "POST",
url: "some.php",
name: 'John',
url: url,
success: function(msg){
alert( "Data Saved: " + msg );
});
It would be better to pack all data with JSON as above, and build the URL server-side as part of whatever script you have handling this AJAX request. 最好像上面那样用JSON打包所有数据,并在处理此AJAX请求的任何脚本中构建URL服务器端。
将数据放入JSON中。
data: {id: '123', sid: '321'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.