php - How to integrate AJAX into a MVC-style web application? -
i'm developing web application using simple (maybe not mvc-compliant) mvc framework, coded myself while developing application keep code clean. application, though, has many ajax components , i'm stuck trying integrate them within general mvc structure. how should integrated?
i have in javascript files:
$('#pagelist').load(base_site_url + 'ajax/pagelist.php');
and pagelist.php used have structure following one:
<?php require '../includes/config.inc.php'; require base_path . 'includes/init.inc.php'; // whole load of controller logic here , then... echo "<table>"; //display user data echo "</table>";
i'm confused this, advice appreciated
few pointers - website should functional without javascript. example, if have pagination page urls /list/?page=1 ... /list/?page=n should make sure of pages clickable without needing javascript.
javascript should extension website. in above example, can come , use js replace functionality of pagination simple ajax behavior. want use jquery.load like:
$("div.content").load("/list/?page=2 div.content > *");
note selector after load. important because haven't created new html pages make website ajax enabled. instead use available browser simple url , load using ajax.
of course, there times need ajax content won't exist on url. in situation recommend creating controller ajax stuff , rendered each path view.
i hope helps.
Comments
Post a Comment