admin管理员组文章数量:1323560
I have an ajax call as
$.ajax({
url: 'url¶1=' + JSON.stringify(obj),
type: 'POST',
async: true,
contentType: 'application/json',
data: {},
success: function(data){
},
error: function(error){
}
});
In the url i get %22
for every "
How can that be escaped?
I have an ajax call as
$.ajax({
url: 'url¶1=' + JSON.stringify(obj),
type: 'POST',
async: true,
contentType: 'application/json',
data: {},
success: function(data){
},
error: function(error){
}
});
In the url i get %22
for every "
How can that be escaped?
Share Improve this question asked Jun 3, 2014 at 19:13 user544079user544079 16.6k42 gold badges120 silver badges172 bronze badges 1-
2
You are sending your
json
data in URL query string and sendingdata:{}
in atype: "POST"
, oh boy, I think there are far more optimization options than just escaping the"
. Try a different approach, usedata
for postingPOST
data. That would be the best solution. – brainless coder Commented Jun 3, 2014 at 19:18
3 Answers
Reset to default 4Maybe this will help
url: 'url¶1=' + encodeURIComponent(JSON.stringify(obj)),
%22 is the "escaped" value for a double quote. It's the accepted way to send that data in a URI. Where exactly are you running into a problem?
The JSON.stringify converts the object into a string. However, a string with quotes must be converted to a URL encoded string (see superrafal's answer).
However, if this is a POST request, why are you sending parameters in the URL as a query string (?key=value) like a GET request? The data parameter is set to a blank object. If you desire to send those values in the URL as a GET, change the type to GET, remove the "data" parameter, and use $.param(obj) to convert that object to a query string. If you desire to send those values as a POST, use the following:
$.ajax({
url: "url_to_file_to_accept_POST_request",
type: "POST",
data: obj,
success: function(data) {
},
error: function(error) {
}
});
本文标签: javascriptescape double quotes in url of ajax callStack Overflow
版权声明:本文标题:javascript - escape double quotes in url of ajax call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742117727a2421545.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论