It is still common for xhr (XMLHttpRequest) to send post text data. You can directly call "xhr. Send (data.
However, the processing of binary data is a little complicated.
However, in firefox3, you can use the following method to debug ajax to send post binary data:
Script code:
<SCRIPT type = "text/JavaScript"> <! -- <Br/> function test () {<br/> var DATA = prompt ('Enter the data (grep HEX ):',''); <br/> DATA = eval ('"' + Data + '"'); // parses binary data into a string. <br/> var xhr = new XMLHttpRequest (); <br/> xhr. onreadystatechange = function () {<br/> If (xhr. readystate = 4 & xhr. status = 200) {<br/> alert (xhr. responsetext); <br/>}< br/>}; <br/> var url = '/some. action '; <br/> xhr. open ('post', URL, true); <br/> // xhr. send (data); // This method may not work due to Encoding Restore to raw data. <Br/> xhr. sendasbinary (data ); <br/>}< br/> // --> </SCRIPT> <br/> <input type = "button" value = "ajax" onclick = "test (); "/>
Auxiliary tool: winhex 15.6
Steps:
1. Use winhex to open the binary data file, or directly edit the binary data in winhex.
2. select Edit> copy> grep hex from the winhex menu to copy the binary data to the clipboard in the format of/xnn.
3. Run the script code above and enter the copied data as prompted.
You can use firebug to debug related request data.
Note:
Because binary data is not easy to express, we first use winhex to convert the data to "grep hex" text and input it to the script.
The script parses "grep hex" into a two-byte string saved in Javascript. This string is characterized by a one-to-one correspondence between the low byte of each character and each byte of the binary.
In ff, the parameter "data" of the "xhr. Send (data)" method can be a specific object or a string.
For a string, it is converted to binary according to a certain encoding (which is tested to look like a UTF-8), which cannot be restored to the original binary data.
However, FF also provides an "xhr. sendasbinary (data) "method. This method accepts a string as a parameter. It discards the high byte of each character and only keeps the low byte, so that it can be restored to our original data.
The implementation of this "tool" is still simple, but it is a little troublesome to use.
For further exploration, it seems that you can select a file through the file dialog box to directly read and send the content, but the implementation is more troublesome.
PS: "xhr. sendasbinary (data)" is not a standard method, so it can only be used in ff3.
Refer:
Https://developer.mozilla.org/en/XMLHttpRequest#sendAsBinary ()