Slain W. wrote:
Fred wrote:
I believe this is what respond_to is for:
respond_to do |wants|
wants.html {#render some html}
wants.js do {#render some rjs}
end
Fred
Actually, this doesn’t work. link_to_remote :update => ‘some_div’
triggers the wants.js even though it really only wants.html by
definition.
There is a problem in prototype 1.5.0_rc0 in setRequestHeaders causing
this:
‘Accept’, ‘text/javascript, text/html, application/xml, text/xml,
/’];
will ALWAYS trigger the wants.js in a link_to_remote :update and never
the wants.html. The request headers for an Ajax.Request and an
Ajax.Updater should be different…
Update should be:
‘Accept’, ‘text/html, text/javascript, application/xml, text/xml,
/’];
and request should be
‘Accept’, ‘text/javascript, application/xml, text/xml, /’];
I’m thinking. Or else, rails needs another way of knowing whether html
or js is wanted…
Adding a custom setRequestHeaders to Ajax.Updater that omits the
javascript option works as well…
setRequestHeaders: function() {
var requestHeaders =
[‘X-Requested-With’, ‘XMLHttpRequest’,
‘X-Prototype-Version’, Prototype.Version,
‘Accept’, ‘text/html, application/xml, text/xml, /’];
if (this.options.method == 'post') {
requestHeaders.push('Content-type', this.options.contentType);
/* Force "Connection: close" for Mozilla browsers to work around
* a bug where XMLHttpReqeuest sends an incorrect Content-length
* header. See Mozilla Bugzilla #246651.
*/
if (this.transport.overrideMimeType)
requestHeaders.push('Connection', 'close');
}
if (this.options.requestHeaders)
requestHeaders.push.apply(requestHeaders,
this.options.requestHeaders);
for (var i = 0; i < requestHeaders.length; i += 2)
this.transport.setRequestHeader(requestHeaders[i],
requestHeaders[i+1]);
},