Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it best practice to create new class for each jQuery call?
    text
    copied!<p>I have a directory tree structure. Each time I click a folder, <code>jQuery.ajax</code> fires and opens a <code>jquery.php</code> file.</p> <p>This is my javascript code that triggers the jQuery.ajax:</p> <pre><code> jQuery('.directory').live('click',function() { // Get dir name clicked var dir = jQuery(this).find('span').html(); // Update dir list getHTML('getDirList',dir, function(html){ jQuery('#fileDirList').html(html); }); // Update file list getHTML('getRowList',dir, function(html){ jQuery('#fileList').html(html); }); }); function getHTML(instance, dir, callback) { jQuery.ajax({ type: "POST", url: "../wp-content/plugins/wp-filebrowser/jquery.php", dataType: 'html', data: {instance: instance, dir: dir}, success: function(html){ callback(html); }, error: function(e) { callback('[Error] ' + e); } }); } </code></pre> <p>In this file I have the following code in my jQuery.php file:</p> <pre><code>&lt;?php class jQueryFactory { /** * Get and output directory list */ public function getDirList() { echo parent::getDirList(); } /** * Get images and list them in row format */ public function getRowList() { echo parent::getRowList(); } /** * Create new directory */ function createDir() { if(isset($_POST['new_dir'])) { $result = parent::createDir($_POST['new_dir']); echo $result; } } /** * Delete file */ function deleteFile() { if(isset($_POST['file'])) { $file = $_POST['file']; parent::deleteImage($file); } } } // Does this work? if(!isset($factory)) $factory = new jQueryFactory(); switch($_POST['instance']) { case 'deleteImage' : $factory-&gt;deleteFile(); break; case 'createDir' : $factory-&gt;createDir(); break; case 'getDirList' : $factory-&gt;getDirList($dir); break; case 'getRowList' : $factory-&gt;getRowList($dir); break; } ?&gt; </code></pre> <p><strong>My question is:</strong> Do I have to fire this function each time I click? Or can I fire once and then just call the various functions within the same user session?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload