how to call ajax code from an external js file

Posted on 2014-07-14
Last Modified: 2014-07-14
I use this code to create jquery dialog and CKEditor instance

 <input class="boton_fancybox" onclick="createEditor(this);" id="boton_texto" type="button" style="text-decoration:none;" value="Editar el contenido de este campo">

<textarea rows="5" class="campo" cols="90" id="texto" name="texto" style="display:none;"></textarea>

<script type="text/javascript" src="../../contenidos/ckeditor5/ckeditor.js"></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<link rel="stylesheet" type="text/css" href="" />    
<script type="text/javascript">
var editor, html = '';
var config = {};

function createEditor(campo)
 var temp ="_");

       if ( editor )

        $("#div_"+temp[1]).bind('dialogopen', function() //JQ
                editor = CKEDITOR.replace( temp[1],
						height:"600", width:"780",
						toolbar: [
	{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
	{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
	{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
	{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote' ] },
	{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
	{ name: 'insert', items: [ 'HorizontalRule', 'SpecialChar', 'Iframe' ] },
	{ name: 'tools', items: [ 'Maximize' ] },
	 { name: 'colors', items: ['TextColor', 'BGColor'] }

		enterMode : CKEDITOR.ENTER_BR,
						shiftEnterMode: CKEDITOR.ENTER_P
        }).bind('dialogclose', function()
        .dialog({autoOpen: false,
                maxHeight:0.95 * $(window).height(),//1
                width: 800,
                modal: false,
                position: 'top',
                resizable: false,
                autoResize: true }).dialog('open');

function removeEditor()
        if ( !editor )

        editor = null;

Open in new window

I tried to use createeditor() and removeeditor() in an external js file to use them in other file but they doesnt works.

I there way to use my code in an external js file????
Question by:altariamx2003
    LVL 30

    Accepted Solution

    Of course there is, just make sure you reference your js file AFTER the ckeditor.js reference.

    Also make sure the DOM is ready...
    The easiest way is to declare your script last thing before the end of the </body>

    This way you're sure all dependencies are loaded and the DOM is ready.
    Also like this you don't need to use jquery DOM ready function.

    Author Comment

    So easy!!!!!!!

    Mr. Simoes you are a genius!!!!!!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now