Reputation: 7092
I currently have my TinyMCE init statement inside the 'done' method of my ajax call like this:
$(document).ready(function () {
$.ajax({
url: '/api/GameData/' + gameID,
method: 'GET',
dataType: 'json',
success: function (data) {
},
fail: function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
}
}).done(function (data) {
$("#gameEditor").val(data);
tinyMCE.init({
selector: 'div#gameEditor',
inline: true
});
});
});
function saveTinyMCE() {
var text = tinyMCE.get('gameEditor').getContent();
}
I have a save function that uses jquery ajax to post data. I have this function defined outside the done function.
Everytime the page loads, I get this error for the 'var text =' line in the saveTinyMCE function in the browser console:
Uncaught TypeError: Cannot read property 'getContent' of null
Do I need to put this save function inside the 'done' part of the initial ajax call as well?
Thanks!
Upvotes: 0
Views: 426
Reputation: 247
I think you need to call tinymce.init outside of ajax method. Example: Write init function :
$(document).ready(function () {
var self = this;
self.initTinyMCe (){
tinyMCE.init({
selector: 'div#gameEditor',
inline: true
});
}
$.ajax({
url: '/api/GameData/' + gameID,
method: 'GET',
dataType: 'json',
success: function (data) {
},
fail: function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
}
}).done(function (data) {
$("#gameEditor").val(data);
self.initTinyMCe();
});
});
Upvotes: 1