to add a jQuery event to an Ajax link in CakePHP I used the following way,
<?php echo $this->Js->link(TITLE, array('controller' => 'CONTROLLER', 'action' => 'ACTION'), array('update' => '#DIV_ID', 'class' => 'FixAjaxReload') ); ?>
which becomes a HTML link and the following JQuery
jQuery('a.FixAjaxReload').on('click', FUNCTION);
on the other hand I need to add an event to the link,
(function(){jQuery("body").on('click', 'a.FixAjaxReload', function(event){
var linkTo = jQuery(this).attr('href');
if (navigator.appName.indexOf("Internet Explorer") > 0) {
window.location.hash = '!' + linkTo.replace(window.baseUrl, '/');
} else {
window.history.pushState('', linkTo, linkTo);
}
});})();
- I used the selector syntax in the second event, because the link might be loaded by ajax call
- I used the other syntax in the first event(i.e. didn’t change the CakePHP way), because if I did the event will be called multiple times (no. of previous Ajax calls)
but some how they don’t work together
any ideas???
thanks in advance
thank you for your help
I found the solution
I edit the Cake Engine as follow,
in JQueryEngineHelper file –> event function
I replaced “return false;” with “event.preventDefault();”
the Problem wasn’t conflict between the two syntax as I thought, It was the “return false;” statement preventing the next scripts from being executed
thanks again