Forums / Cotonti / Support / Ajax URLs - Need help understanding them.

lukgoh
#1 2013-11-13 17:30

Hello, I'm looking for more information on better understanding how to render ajax urls from Cotonti's core functionality. 

I understand cot_pagenav() works really well on creating ajax friendly page navigation, but I am struggling to understand how (if possible) to achieve a similar ajax friendly url using cot_url(). I understand for ajax to work you need to include class="ajax" and have a rel=" -- ajax or hash url here --" but I am struggling to clearly understand hot to achieve this. 

 I am currently trying to use a dropdown select box to refresh the plugin (and only the plugin, instead of the whole page) like found in the user list part of the frame work, except without refreshing the enitre page.

Luke.

Macik
#2 2013-11-13 22:53

All Cotinti Ajax helper functions is coded for user actions like click for «ajaxed» link or «ajaxed» form submit.

So better way to implement your function is to write own JS code and bind it to select change event. Something like that (should works only with jQuery and Ajax setting enables in Admin panel):

$('#mySelect').change(function() { 
    ajaxEnabled && ajaxSend({
            method: 'GET',
            url: 'url/to/your/app',
            divId: 'targetBlockID'
        });
});

Or something like this in native JS — should work (but not tested) without jQuery and Ajax enabled settings.

var mySelect = document.getElementById('mySelectBoxId');
mySelect.onchange = function() {
  var xhr = new XMLHttpRequest(); 
    xhr.open('GET', '/url/of/your/app', true); 
    xhr.onreadystatechange = function() {  
      if (xhr.readyState != 4) return; 
      outputElem.innerHTML = xhr.responseText; 
    }
    xhr.send(null); 
}

[By the way - this native code is not actually crossbrowser.]

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
lukgoh
#3 2013-11-15 11:00

Thank you for your help Macik.