0

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:

enter image description here

The actual form data being sent (network tab in developer console)

enter image description here

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.

BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
  • Can you please post an example of action.payload (just before running the ajax) and the error you get? – jacekbj May 21 '18 at 12:12
  • @dzejdzej I've just posted them now in the images. The error is in the Elixir programming language. I just posted the image which shows the ampersand breaking the string in the shop name. – BeniaminoBaggins May 21 '18 at 12:41

0 Answers0