Help with Ajax in ColdBox app


I’m having a problem using Ajax with my ColdBox app. I am following the directions located at the following url:

In my setup I have a handler named “newsletterSubscriber” and a method named “doSignUp” which takes an email address submitted with Ajax and inserts it into the database. Simple enough.

Here is my Ajax script (using Prototype):

function init(){
function persistAddress(e){
$(‘response’).innerHTML=‘Adding email address…’;
var pars = ‘email=’ + escape($F(‘email’));
var myAjax = new Ajax.Updater(‘response’,'NewsletterSubscriber.doSignUp ', {method: ‘get’, parameters: pars});

The init() function is an event handler that is fired when the newsletter form is submitted. The persistAddress() function sends the email address to " NewsletterSubscriber.doSignUp" which should insert the email and return a string confirming success or failure.

Unfortunately, when the form is submitted I get an error stating that “t he requested URL /NewsletterSubscriber.doSignUp was not found on this server.”

What am I doing wrong? I’m sure it must have to do with this line:
var myAjax = new Ajax.Updater(‘response’,‘NewsletterSubscriber.doSignUp’, {method: ‘get’, parameters: pars});

Am I supposed to put something other than “NewsletterSubscriber.doSignUp” for the url to submit to?

Thanks for your help,

Ah, I figured it out. Simple mistake, really. It was hard to debug though because ColdBox apparently caches the scripts. When I would change the AJAX script I retry it the old script would continue to be used (from cache?).

Anyways, the fix was changing the url to “index.cfm?event=NewsletterSubscriber.doSignUp”. I forgot the “index.cfm?event=” part because I starting getting used to SES urls with ColdCourse.


I don't know how it would cache the scripts Aaron, since there is
nothing in ColdBox for event caching, yet!
As for your correction, yes, you need to pass in the full url. I
usuallly create a proxy function that handles my framework ajax calls,
basically the following:

function doFormEvent (e, targetID, frm) {
  var params = {};
  for(i=0;i<frm.length;i++) {
    if(!(frm[i].type=="radio" && !frm[i].checked)) {
      params[frm[i].name] = frm[i].value;
  doEvent(e, targetID, params);

function doEvent (e, targetID, params) {
  var pars = "";
  for(p in params) pars = pars + p + "=" + escape(params[p]) + "&";
  pars = pars + "event=" + e;
  var myAjax = new Ajax.Updater(targetID,
                  {method:'get', parameters:pars, evalScripts:true,
onFailure:h_callError, onComplete:doEventComplete});
  $("loadingImage").className = "showlayer";

Its also on prototype, hope this helps too.You can then call it like

doEvent("ehFeed.dspViewFeed", "centercontent", {feedID:feedID});