Quantcast
Channel: General developer forum
Viewing all articles
Browse latest Browse all 37687

Re: Discussion: Best way of making JS/YUI widgets work with AJAX

$
0
0
by Davo Smith.  

AJAX_SCRIPT has been there since Moodle 2.0 (unless I'm mistaken).

You might want to consider the following variation on your AJAX page:

ajax-page.php:

define('AJAX_SCRIPT', true);
require_once('../../config.php');
require_once('lib.php');
myclass::view();
 

view.php:
require_once('../../config.php');
require_once('lib.php');
...
echo$PAGE->header();
myclass::view();
echo$PAGE->footer();
 

lib.php:

class myclass {
  public staticfunction view(){
     echo html_writer::tag('p', 'Hello world!');
  }
}

By routing most of your logic through a class in a library file, you eliminate many of the problems of multiple entry points, whilst retaining much of the code clarity that comes from them.

 


Viewing all articles
Browse latest Browse all 37687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>