1

I have one json string , string is below.

 {  
   "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":""
}

When i pass this data using http and post method then string is break after & sign.

My http post request code is like this.

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);
                    });

What is passed in this request , please find below screen shot of the network.click here

This screen shot is after remove 'data=+' remove from request: click here

data is break after & in relation key.

Please help me to solve this problem. Thanks in advance

test test
  • 33
  • 5

1 Answers1

0

use encodeURIComponent() function.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

Kavindra
  • 1,697
  • 2
  • 14
  • 19
  • there is problem with content-type , content-type is `x-www-form-urlencode` , i change this to `application/json` and it is working now – test test Jul 20 '17 at 09:01