0

I am trying to send a JSON string along with the url ass http get using angular's $http service but somehow the curly braces are being removes when the request is sent because of may be angular's URI encode function is not working correctly, is there any work around for this? the samlpe would be if I send

http://someurl.com?a={"a":"b"} 

it is sent to server as

http://someurl.com?a="a":"b" 

I dont know whats wrong with Angular.

Faizan Ali
  • 509
  • 12
  • 35
  • Show your actual code. I suspect you'll have to override `paramSerializer` – Phil Jul 08 '15 at 23:41
  • 4
    (1) Try `JSON.stringify()` (2) GET requests shouldn't be used like that. You should only need to send minimal, specific information as query parameters, not a full JS object. (3) Use a POST request for sending data to the server. – HankScorpio Jul 08 '15 at 23:42

2 Answers2

1

Use JSON.stringify to convert your url object into a JSON text. Then use encodeURIComponent(JSON_text) to encode the url.

Mr.Green
  • 274
  • 1
  • 3
  • 15
0

It is to do with URI encoding.

Take a look at the following question for your answer:

How to escape a JSON string to have it in a URL?

;)

Community
  • 1
  • 1
Craig Mayers
  • 185
  • 2
  • 9