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.
Can somebody help with a wise solution.
Thank in advance.
Pass an object instead of string for the data
field:
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中。
data: {id: '123', sid: '321'}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.