I’d like to set overrideMimeType(“application/json”); when using Ajax.Request.
As far as I can tell I think I should be using the onCreate option, like so:
new Ajax.Request("x.json", {onCreate: function() {...}});
and then set overrideMimeType("application/json"); on the xhr, except I’m not sure how to reference the xhr from this onCreate function. The xhr is not this and it’s not arguments[0] afaict.
How do I set overrideMimeType("application/json"); on the xhr?
In your
onCreatefunction try adding this:arguments[0].request.transport.overrideMimeType('application/json');or:
arguments[0].transport.overrideMimeType('application/json');This is a bit of a hack, Prototype has chosen not to expose this functionality in their API, presumably because it is not cross-browser safe. To that point, you should be aware that overrideMimeType is not available in IE or Opera. If you still want to use it you should ensure that you check from the presence of the method on the XMLHttpResponse object.
Hope this helps.