March 05, 2014

March 05, 2014
AJAX is about updating parts of a web page, without reloading the whole page. We need ajax many times to create a dynamic web application. In this article, we are going to discuss about easiest way to use the Ajax in Cakephp controller action. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

In cakephp, to manipulate data by ajax we need to call some controller's action with some parameters, by the following ajax call we can easily pass the parameters to that action.

Example of ajax implementation in cakephp

<script>
$(document).ready(function(){
$.ajax({
    dataType: "html",
    type: "POST",
    evalScripts: true,
    url: '<?php echo Router::url(array('controller'=>'admin_employees','action'=>'emp_return'));?>',
    data: ({dutylocation:dloc,dutytype:dtype}),
    success: function (data, textStatus){
        $(".UserInfoDiv").html(data);

    }
});

});
</script>
<html>
<div class='UserInfoDiv'></div>
</html>

0 comments:

Post a Comment