javascript - Force encoding used in XHR request -


in browser extension i'm developing, i'm doing xhr request load data, using jquery:

$.get(url).done(function(data, textstatus) {     console.log(data); }) 

the remotely-loaded data windows-1252 encoded csv file served content-disposition:attachment , without mime-type/charset header (i don't have control on backend, can't fix that).

how can force browser decode response windows-1252 instead of utf-8 apparently does?

as hinted previous research , first answers, couldn't find way wanted using jquery. worked around issue using vanilla xmlhttprequest responsetype=blob, explained in https://developer.mozilla.org/en-us/docs/web/api/xmlhttprequest/sending_and_receiving_binary_data

var oreq = new xmlhttprequest(); oreq.open("get", url, true); oreq.responsetype = "blob"; oreq.onload = function(e) {     var blob = new blob([oreq.response], { type : 'text\/csv' });     account.data = blob; } oreq.onerror = function(e){     ... } oreq.send(); 

fortunately, using blob post data server i'm saving decoding/encoding step here...


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -