locked
XHR to retrieve binary rather than text/xml? RRS feed

  • Question

  • Hi. I am making requests to a server that returns binary data. For example a url on the server might return an image or an mp3 file. Is there anyway to use the XHR object to make a request to the server,  but have access to the returned data as binary data, rather than only responseText or responseXML? I have seen that there are responseBody and response values within the XMLHttpRequest, but they seem to always have the same contents as responseText. Any thoughts?

     

    Any help would be greatly appreciated!

    - Joe


    • Edited by Joe Levy_ Friday, December 16, 2011 11:42 PM
    Friday, December 16, 2011 11:40 PM

Answers

  • Figured it out.

    For anyone with a similar problem, Internet Explorer 10 and Windows 8's XMLHttpRequest object has a responseType value, that when set to 'blob', will return the contents of the url as a stream. All you need to do to take advantage of this in Windows 8 when using WinJS.xhr is to pass it responseType: "blob" as part of the options object parameter supplied to WinJS.xhr

    See: http://msdn.microsoft.com/en-us/library/hh673569(v=vs.85).aspx

    Saturday, December 17, 2011 8:28 AM