The problem is in the difference how browsers implement simple calls. The problem occurs while using colorbox extenstion (facebox variant). Content is loaded into colorbox with jquery load() function.
When the call is made by Chrome, Accept header is set to:
Accept: text/html, */*, text/javascript
In case of FireFox, header looks like this:
Accept: text/javascript
I tried to force the Accept header by setting it using:
jQuery.ajaxSetup({
'beforeSend': function (xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});
It works well while using $.ajax calls, but it doesn’t seem to affect .load function. Any
idea how to solve this issue?
Even though it’s obviously better to avoid the issue by using the
$.ajaxcall directly, you can create a proxy method for the$.ajaxmethod. This helps since$.loadin turn calls$.ajaxwith a set of default parameters. We can therefore intercept$.loads call to$.ajax.Try
Obviously, this will affect ALL calls to
$.ajax, so you might want to add another parameter to the proxy method which can be set and checked in the proxy to to avoid setting requestheader when called directly. Or in settings even.I guess you could also add/remove the proxy for each call, but this adds overhead and might lead to race conditions(?) (Wouldn’t think so if you remove the proxy straight after the request, don’t wait for callback), so you’d need a lock of some sort.
EDIT: Added
settings['accepts'] = null;to keep$.ajaxfrom adding any headers before the callback assetRequestHeader()only adds, not replaces. Boy this is dirty.EDIT 2: Actually, a perhaps cleaner option would be to set up your own accepts and refer to them to allow
$.ajaxto do its job to map the data types and set up XHR all by itself: