How do you capture the response text for an ajax:success event handler?
I am probably missing something obvious, but I'm new to Prototype, coming from jQuery. I have a link created using link_to and remote=>true that output an AJAX link that is working.
Here is the JS I have:
Event.observe(window, 'load', function() {
$$('.checkoff-link').each(function(element) {
element.observe('ajax:success', successfulCh开发者_JAVA技巧eckOff);
});
});
// when they tick it off, check it off
function successfulCheckOff(e) {
// shrink and strike out the text
var element = e.element();
var label = $(getLabelIdFromLinkId(element.id));
label.addClassName('strikeout');
}
How do I get the responseText of the ajax request? I'm trying to pass data back from my controller on success, and I don't know how to capture it in the JS tier.
I figured this out using this handy tutorial: https://github.com/rails/prototype-ujs
Essentially, all of the response information is stored in event.memo, so you can use code like this:
var response = e.memo;
To then access everything you need.
And you can get the HTML/Text/JSON from the response using the responseText method:
var html_return = e.memo.responseText;
精彩评论