MODX Community

Can't get ajax working in custom JS for Collections column

I’m trying to pull some custom data for display in a Collections column, but the Ajax seems to be not working at all. The URL never gets called, or if it does no response is received. I have verified that the URL works. I know the script is being called, because if I make it just return a specific value, it shows up in the column. Here’s the test Collections JS function:

Collections.renderer.tagfield = function(value, metaData, record, rowIndex, colIndex, store) {
  Ext.Ajax.request({
    url: "/provtag",
    success: function(response, opts) {
      return "yes";
    },
    failure: function(response, opts) {
      return 'NO';
    }
  });
};

Any ideas?

I did get this to work using jQuery instead of ExtJS, but it’s absurdly slow, so it’s actually not a useful technique.

FYI, even this doesn’t work:
var resp;
Ext.Ajax.request({
method: ‘POST’,
url: “/provtag”,
async: false,
success: function(response, opts) {
resp = ‘yes’;
},
failure: function(response, opts) {
resp = ‘NO’;
}
});
return resp;

A renderer expects a response immediately (synchronously). An asynchronous request cant be used to fill that.

It doesn’t work even if I turn off async. As I said above, it works if I use jQuery, but ExtJS doesn’t work, even with “async: false” added.

Anyway, snippet renderers work way better. Just thought I would try this to see if it had any benefit.

From what I’ve seen, the async parameter may not have been introduced until a later version of ExtJS, which may explain why it’s having no effect for you.

One thing to note when using the Ext.Ajax or MODx.Ajax classes is that success and failure parameters fire functions depending upon whether or not the script was able to run, and have nothing to do with the value being returned from your script.

It may be a much easier task to use a snippet renderer instead of a javascript one. With that in mind, how should your renderer change the value and what is your provtag script supposed to return?