使用的是3.14.1版本
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER
xhr:open("GET", url)
xhr.tag = tag
local function onCallBack()
if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then
local response = xhr.response
local size = table.getn(response)
local file = io.open(path,"w")
for i=1,size do
file:write(string.char(response[i]))
end
file:flush()
file:close()
self:createImg(path)
else
print("xhr.readyState is:" .. xhr.readyState .. " xhr.status is: " .. xhr.status)
G_GlobalFunc:showAlertLayer(self._widget,"获取失败")
end
xhr:unregisterScriptHandler()
end
xhr:registerScriptHandler(onCallBack)
xhr:send()