I'm trying to load a script file via $.ajax and also set some headers in the request, is this possible? It seems to work in chrome but not firefox, the file loads and I can see it in the scripts tab of firebug but in the callback when I try to use the script I get an error.
If I remove the headers from the request then it works fine. but I need to have the headers added to the request.
I'm not using $.getScript as it does not allow headers to be set.
I would like form thing like this:
$.ajax({
url: '/somefile',
contentType: 'application/javascript',
headers: { someheader: 'somevalue'},
type: 'get',
success: function(data){
eval(data); // dont seem to need this in chrome
doSomethingWithNewScript();
}
});
Update the error is not an error with making the request. I get 'doSomethingWithNewScript' not defined when I try and use the script. so its as if the request is fine but firefox cant use the script.
The headers set are custom headers like 'X-Username': 'dave'