我有一个 json 字符串,字符串在下面。
{
"assigned_to":1,
"type":0,
"email":[
{
"value":"mobile@gmail.com",
"is_primary":1,
"type":1,
"type_id":1
}
],
"first_name":"Mr Mobile",
"salutation_id":1,
"links":[
{
"company":"Mobile",
"relation":"CEO & Founder",
"cmp_id":1
}
],
"phone":[
{
"code":"",
"value":"",
"is_primary":1,
"phone_type":"1",
"country_code_value":""
}
],
"photo":"",
"last_name":""
}
当我使用 http 和 post 方法传递此数据时,字符串在 & 符号后断开。
我的http post请求代码是这样的
NOTE: JSON.stringify(this.formData) returns above string
$http.post(APP.API + 'contacts', 'data=' + JSON.stringify(this.formData)).
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
// debugger;
Notification.error(data.msg);
});
这个请求传递了什么,请看下面的网络截图。 click here
此屏幕截图是在从请求中删除“data=+”之后:click here
数据在关系键 & 之后中断。
请帮我解决这个问题。提前致谢
最佳答案
使用 encodeURIComponent() 函数。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
关于jquery - 当 json 字符串中有 & 登录时,http post 请求中的数据中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45207329/