TypeError: window.tinyMCE.execInstanceCommand is not a function

https://stackoverflow.com/questions/22813970/typeerror-window-tinymce-execinstancecommand-is-not-a-function

Thanks to Scott B

In WordPress 3.9, the TinyMCE is updated to version 4, and in TinyMCE 4, the method “execInstanceCommand” has been replaced by the method “execCommand”.

For compatibility issue (with old versions of WP), you must be check the TinyMCE version and used the suitable method.

In below, i changed your code. The commented lines of code are mine.

function submitData($form) {
    try {
        $form = $form || jQuery('form');
        if(window.tinyMCE) {

            /* get the TinyMCE version to account for API diffs */
            var tmce_ver=window.tinyMCE.majorVersion;

            var selectedContent = tinyMCE.activeEditor.selection.getContent(),
                id = tinyMCE.activeEditor.editorId || 'content',
                shortcodeName = $form.attr('name'),
                shortcode=" [" + shortcodeName + ' ';

            $form.find('[data-name]').each(function() {
                var $this   =   jQuery(this),
                    type    =   $this.data('type'),
                    value   =   ($this.attr('type') == 'checkbox')
                            ?   ($this.is(':checked')) ? 'on' : ''
                            :   $this.val() || '';
                value = fitValue(type, value);
                shortcode += $this.data('name') + '="' + value + '" ';
            });
            shortcode += ']' + selectedContent + '[/' + shortcodeName + '] ';

            /* Check for TinyMCE version */
            if (tmce_ver >= 4) {
                /* In TinyMCE 4, we must be use the execCommand */
                window.tinyMCE.execCommand('mceInsertContent', false, shortcode);
            } else {
                /* In TinyMCE 3x and lower, we must be use the execInstanceCommand */
                 window.tinyMCE.execInstanceCommand(id, 'mceInsertContent', false, shortcode);
            }
            tinyMCEPopup.editor.execCommand('mceRepaint');
            tinyMCEPopup.close();
        }
    } catch (e) {
        console.error(e);
    }
    return;
}