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开发者_如何学Go 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.
Put your data in a JSON.
data: {id: '123', sid: '321'}
精彩评论