roblade
roblade
  • 发布:2016-05-11 10:54
  • 更新:2016-05-11 17:40
  • 阅读:1388

XMLHttpRequest post send 如何发送buf?

分类:HTML5+
```javascript  
    var xhr = new plus.net.XMLHttpRequest();  
xhr.responseType = "arraybuffer";  
    xhr.onreadystatechange = function () {  

}  
    var myArray = new ArrayBuffer(256);  
    var longInt8View = new Uint8Array(myArray);  

   for (var i=0; i  < longInt8View.length; i++) {  
     longInt8View[i] = i % 255;  
    }  
    xhr.open( "POST", url );  
xhr.send(longInt8View);  

    比如发送的时候是 233 服务端收到 50 51 51 变成了字符“233”,并且还会有分隔符,求解!!!
2016-05-11 10:54 负责人:无 分享
已邀请:
roblade

roblade (作者)

function loadXMLDoc(url, val)  
{  
    if ( xmlhttp ) {  
        if ( xmlhttp.readyState != 4 ) {  
            xmlhttp.abort();  
        }  
        xmlhttp = null;  
    }  

if (window.XMLHttpRequest)  
    {// code for all new browsers  
xmlhttp=new XMLHttpRequest();  
}  
else if (window.ActiveXObject)  
{// code for IE5 and IE6  
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
}  
if (xmlhttp!=null)  
{  
xmlhttp.onreadystatechange=state_Change;  
xmlhttp.open("POST",url,true);  
xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded');  
console.log("just send");  
xmlhttp.send( val);  
}  
else  
{  
alert("Your browser does not support XMLHTTP.");  
}  
}  

function state_Change()  
{  
if (xmlhttp.readyState==4)  
{// 4 = "loaded"  

if (xmlhttp.status==200)  
   {// 200 = OK  

// ...our code here...  

alert(xmlhttp.responseText);  
   }  

else  
   {  

alert("Problem retrieving XML data "   xmlhttp.status);  
   }  
}  
}  

function sendHttpRequest()  
{  
    console.log("send request");  
    var myArray = new ArrayBuffer(256);  
    var longInt8View = new Uint8Array(myArray);  

    for (var i=0; i< longInt8View.length; i++) {  
      longInt8View[i] = i % 255;  
    }  
    loadXMLDoc("http://192.168.1.102:8080/src/com/phei/netty/",longInt8View)  

}

换成ajax的写法就正确了,遇到过类似问题的给解答下,谢了!

该问题目前已经被锁定, 无法添加新回复