What data formats can AJAX transfer?

后端 未结 7 1870
梦毁少年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:51

    You can send anything you like, the problem may be how to handle it once you get it ;)

    Standard HTML is probably the most common type of ajax content in use out there - you can choose character encoding too, although it's always best to stick with one type of encoding.

    0 讨论(0)
  • 2021-02-06 01:52

    There is a Digg the Blog entry titled DUI.Stream and MXHR that shows off what they call "Multipart XMLHttpRequests." It is alpha code now, but there is a demo that handles images.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-06 02:01

    You can transfer any type of data either string or bytes

    0 讨论(0)
  • 2021-02-06 02:03

    You can move anything that can be sent over HTTP. There are restrictions about the call being made to the same domain as the page loaded from, but not on the content of the transfer. You can do either GET or POST transactions too.

    0 讨论(0)
  • 2021-02-06 02:13

    Since data is transported via HTTP you will have to make sure that you use some kind of encoding. One of the most popular is base64 encoding. You can find more information at: http://www.webtoolkit.info/javascript-base64.html

    The methodology is to base64-encode the data you would like to send and then base64-decode the data at the server(or the client) and use the original data as you intended.

    0 讨论(0)
提交回复
热议问题