简体   繁体   中英

Angular JS is not encoding JSON correctly to pass with get request?

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.

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

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?

;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM