Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.45k stars 319 forks source link

Saving with javascript ajax(fetch) doesn't work? #214

Closed magicbeanman closed 4 years ago

magicbeanman commented 4 years ago

How do you save with javascript ajax? I have noticed the textarea that this is set does not update, there's some eventlistener to send it or something (not sure how that works)

anyway my code I have to click the save button twice for it to actually POST the new data, the POST request it sends the first time does not have the new data, but the second time it does have the data. It is easyMDE that causes this. All I want to do is be able to click a save button and not have it refresh the entire page to save, so whatever method there is to do that I will use.. as I said my current one works but I gotta click save 2 times. (no jquery please)

method="POST" onsubmit="event.preventDefault(); saveNotesForm(event,this);">

function saveNotesForm(e,form) { var formData = new FormData(form); fetch(form.action,{ method:'POST', body: formData, }); console.log('sent msg'); }

quinnzipse commented 4 years ago

I also use fetch to save the data and I manually append the value of the of the editor to the form data like this: formData.append('content', mde.value());

magicbeanman commented 4 years ago

Oh ok I did not know that is how you can get the form's value with easyMDE.value()

It looks like I can work with that pretty well, thank you