Eranga Kapukotuwa Eranga Kapukotuwa - 23 days ago 10
React JSX Question

draft-js convertToRaw method is not working

I use draft-js-plugins. I used the emoji and the mention plugins together in my Editor. When I am using ,

convertToRaw(contentState)


to save my content data into the db, it shows an error message.


immutable.js:1421 Uncaught TypeError: Cannot read property 'entries' of undefined


But this error only comes when I have used mention in my content. it works fine with plain text and emojis contents. Please help.

Answer

After working with this for a several time I found the reason. Here I am trying to save an immutable content into the DB. And trying to pass that data to the back-end via an Ajax call.

When we post data via an ajax call, we have to use JSON.stringify and application/json; charset=utf-8 as follows.

$.ajax({ url: '/calendar/event/add', method: "POST", dataType: "JSON", data: JSON.stringify(postData), contentType: "application/json; charset=utf-8", }).done(function (data, text) { if(data.status.code == 200){ console.log("Success"); } }.bind(this));