Hello.
I'm trying to create a plugin that loads in the dialog box the html response of an AJAX POST request done in the plugin execution (when I click in the plugin buttom of the toolbar).
The ajax request works fine but the return value is lost when the control returns to html definition in dialog definition
This is my code in plugin/dialog/plugin.js
contents : [ { id : 'plugin_name', label : editor.lang.plugin_name.dialogTitle, elements : [ { type : 'html', html : '<div id="results">' + getValidationResult(editor.getData()) + '</div>' // The returned value in getValidationResult is not returned here, the html content in the dialog box is '<div id="result">undefined</div>' } ] } ]
And the getValidationResult function:
function getValidationResult(data) { var httpRequest = (!window.XMLHttpRequest)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); var passingData = "action=analize&content="+escape(data); httpRequest.open("POST", "url.jsp", true); httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpRequest.setRequestHeader("Content-length", passingData.length); httpRequest.setRequestHeader("Connection", "close"); httpRequest.onreadystatechange = function() { if(httpRequest.readyState == 4) { var result = httpRequest.responseText; // Here, the result variable has the ajax response html return result; } } httpRequest.send(passingData); }
Looking at the Firebug console, the ajax post request is done successfully, and the jsp page returns the right code.
Please, can anybody help me with this problem?
Thank you very much!
Edited:
If I do the request in synchronous mode then the function works fine, but it's not a valid solution for me because the plugin dialog doesn't open until the request finish.
OnLoad
Have you tried modifying the html on the OnLoad event?