I'm using rxjs in my application.
In package.json my rxjs dependency is "rxjs": "^5.2.0"
From that I'm using the ajax module:
import { ajax } from 'rxjs/observable/dom/ajax'
I can't find the documentation for the ajax function.
My code:
let categories = action.payload.subcategories.map(cat => cat.id)
let shop = JSON.stringify(action.payload.shop)
action.payload.categories = JSON.stringify(categories)
action.payload.shop = shop
return ajax
.post('http://192.xxx.xxxx:4000/products', action.payload, {
'Content-': 'application/json'
})
I'm getting an issue where if the shop
object has an ampersand in one of its fields, that breaks the json.stringified object being sent.
How do I allow ampersands in the text fields of the objects being json.stringified without breaking the field?
Do I have to url encode it? It will just mean a bit more work on the back end to decode so I'm looking at my options.
This SO answer seems like an easy way to do it although I'm not using jquery and I don't know how to set request type to data object in the ajax.post
function being used.
action.payload:
The actual form data being sent (network tab in developer console)
I noticed when I used encodeURIComponent()
in javascript it did change the payload massively. I have the backend decoding json currently so would like to avoid changing the payload that much if possible. The back end is in Elixir.