ruby on rails - Ajax call made by jQuery .load function -
the problem in difference how browsers implement simple calls. problem occurs while using colorbox extenstion (facebox variant). content loaded colorbox jquery load() function.
when call made chrome, accept header set to:
accept: text/html, */*, text/javascript
in case of firefox, header looks this:
accept: text/javascript
i tried force accept header setting using:
jquery.ajaxsetup({ 'beforesend': function (xhr) {xhr.setrequestheader("accept", "text/javascript")} });
it works while using $.ajax calls, doesn't seem affect .load function. idea how solve issue?
even though it's better avoid issue using $.ajax
call directly, can create proxy method $.ajax
method. helps since $.load
in turn calls $.ajax
set of default parameters. can therefore intercept $.load
s call $.ajax
.
var org = $.ajax; $.ajax = function(settings){ settings['accepts'] = null; settings['beforesend'] = function(xhr) { xhr.setrequestheader("accept", "text/javascript"); } org(settings); } $("#foo").load("http://fiddle.jshell.net/fpcbj/show/light/");
obviously, affect calls $.ajax
, might want add parameter proxy method can set , checked in proxy to avoid setting requestheader when called directly. or in settings even.
i guess add/remove proxy each call, adds overhead , might lead race conditions(?) (wouldn't think if remove proxy straight after request, don't wait callback), you'd need lock of sort.
edit: added settings['accepts'] = null;
keep $.ajax
adding headers before callback setrequestheader()
adds, not replaces. boy dirty.
edit 2: actually, perhaps cleaner option set own accepts , refer them allow $.ajax
job map data types , set xhr itself:
var org = $.ajax; $.ajax = function(settings){ settings['accepts'] = {"mydatatype" : "text/javascript"}; settings['datatype'] = "mydatatype"; org(settings); } $("#foo").load("http://fiddle.jshell.net/fpcbj/show/light/");
Comments
Post a Comment