What data formats can AJAX transfer?

后端 未结 7 1869
梦毁少年i
梦毁少年i 2021-02-06 01:33

I\'m new to AJAX, but as an overview I\'d like to know what formats you can upload and download. Is it limited to JSON or XML or can you even send binary types like MP3 or UTF-8

7条回答
  •  不知归路
    2021-02-06 01:56

    If we are talking about ajax we are talking about javascript? And about XMLHTTPRequest?

    The XMLHttpRequest which is only a http request can transfer everything. But there is no byte array in javascript. Only strings, numbers and such. Every thing you get from an ajax call is a piece of text (responseText). That might be parsed into XML (which gives you reponseXML). Special encodings should be more a matter of the http transport.

    The binary stuff is not ajax dependent but javascript dependent. There are some weird encodings for strings to deliver byte data inside in javascript (especially for images) but it is not a general solution.

    HTML is not a problem and that is the most prominent use case. From this type of request you get an HTML string delivered and that is added to some node in the DOM per innerHTML that parses the HTML.

提交回复
热议问题