AJAX

To add ajax function into MV, you need to follow the next sequence of steps.

1. Pass the full path to project into JavaScript (add a line with the path into "views/main-header.php" file).

<script type="text/javascript"> var rootPath = "<? echo $mv -> root_path; ?>"; </script>

2. In "views" folder create a new folder (name it "ajax") for the files that will be called with Ajax. Put ".htaccess" file into this folder with an option "RewriteEngine off" in order to block Mod Rewrite. In new version of MV this folder is already created.

4. Create php file, that would accept ajax requests, for example "request.php".

5. In JavaScript on the website add a code to send Ajax request.

6. In "views/ajax/request.php" file write the following code.

<?
include "../../config/autoload.php";
$mv = new Builder();

if(isset($_POST["a"], $_POST["b"]))
{
   //Process the query

   ...

   //Send HTTP headers and query result
   header("Content-type: text/html");
   echo $mv -> products -> display();
}
?>