There was a guide on
venugopal’s blog but the site was hacked as i see now, here’s a copy with the kind help of Google’s cache:
http://webcache.googleusercontent.com/search?q=cache:a7YFVuw6v2QJ:venugopalreddy.com/category/modx/+venugopalreddy.com/+ajax&cd=1&hl=iw&ct=clnk&gl=il&source=www.google.co.il
I Copy&Pasted it for your convinence, it should help in general:
Modx Revolution + Ajax ( by venugopal )
Lot of people asked in the forum how to use ajax in modx with processros,connectors bloblobl
like the core developers said dont use connector for fontend ajax functionality
instead refer a plain dcument for ajax calls
let me tell you how to use this
create a snippet in the backend and name it ajax
copy the code below ,self explanation code with comments as usual dont worry about the $_REQUEST variables now
<?php
$output='';
//this is the processor file name
$procname=$_REQUEST['action'];
//this is what component we are referencing
$comp=$_REQUEST['component'];
//get the processor file with path
$f= $modx->getOption('core_path').'components/'.$comp.'/processors/'.$procname.'.php';
if (file_exists($f)) {
//include that file so the output of the processor is assigned here
$output= include $f;
} else {
$output= 'Action not found: '.$f;
}
//convert the processor output to json format
return $modx->toJSON($output);
now create a document with Ajax name and Alias as ajax
select empty as template check hide from menus and publish it
in the content window call our ajax snippet as not cache-able
[[!ajax]]
guess what we are done with ajax functionality
all you need to do is pass the action,component variables in your javascript
for any ajax request in your site the url for your ajax request is yoursite/ajax if you enabled SEF
otherwise url is yoursite/index.php?id=ajaxdocumentid
for example your submitting form as ajaxsubmit
if your processor is addpoll.php in components/vxpolls/processors/web/addpoll.php
than action is web/addpoll
component is vxpolls
in the form add this variables as hidden inputs
<form id="myForm" action="ajax">
<input type="hidden" name="action" value="web/addpoll" />
<input type="hidden" name="component" value="vxpolls" />
some other form elements
</form>
in my case iam using mootools ajavascript so i need to call $(‘myForm’).send();
so now my form is sent to ajax document(see action of the form)
the ajax page will send the form to core/components/vxpolls/web/addpoll.php
simple right
lets take another example where you want to get poll data from backend/php with ajax iam assuming you are returning json data
var jsonRequest = new Request.JSON({url: 'ajax', onSuccess: function(responce){
alert(responce.pollname)
}}).get({'action': 'web/getpoll', 'component': 'vxpolls'});
all js frameworks support this kind of ajax functionality, sending variables to ajax url
so dont need to worry if your not using mootools
i will tell you when and how to use connectors later
remember connectors are better suits for backend not for frontend
happy coding