mirror of https://github.com/axmolengine/axmol.git
Merge pull request #4807 from dumganhar/iss3291-xmlhttprequest-error-fix-develop
closed #3291: XMLHttpRequest.status needs to be assigned even when connection fails.
This commit is contained in:
commit
831e0b08e0
|
@ -174,15 +174,13 @@ void MinXmlHttpRequest::handle_requestResponse(cocos2d::network::HttpClient *sen
|
|||
CCLOG("%s completed", response->getHttpRequest()->getTag());
|
||||
}
|
||||
|
||||
int statusCode = response->getResponseCode();
|
||||
char statusString[64] = {};
|
||||
sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());
|
||||
long statusCode = response->getResponseCode();
|
||||
char statusString[64] = {0};
|
||||
sprintf(statusString, "HTTP Status Code: %ld, tag = %s", statusCode, response->getHttpRequest()->getTag());
|
||||
|
||||
if (!response->isSucceed())
|
||||
{
|
||||
CCLOG("response failed");
|
||||
CCLOG("error buffer: %s", response->getErrorBuffer());
|
||||
return;
|
||||
CCLOG("Response failed, error buffer: %s", response->getErrorBuffer());
|
||||
}
|
||||
|
||||
// set header
|
||||
|
@ -207,7 +205,7 @@ void MinXmlHttpRequest::handle_requestResponse(cocos2d::network::HttpClient *sen
|
|||
_status = 200;
|
||||
_readyState = DONE;
|
||||
|
||||
_dataSize = buffer->size();
|
||||
_dataSize = static_cast<uint32_t>(buffer->size());
|
||||
CC_SAFE_FREE(_data);
|
||||
_data = (char*) malloc(_dataSize + 1);
|
||||
_data[_dataSize] = '\0';
|
||||
|
@ -546,17 +544,23 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, withCredentials)
|
|||
*/
|
||||
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText)
|
||||
{
|
||||
if (_data)
|
||||
{
|
||||
jsval strVal = std_string_to_jsval(cx, _data);
|
||||
|
||||
if (strVal != JSVAL_NULL)
|
||||
{
|
||||
vp.set(strVal);
|
||||
//JS_ReportError(cx, "Result: %s", data.str().c_str());
|
||||
return JS_TRUE;
|
||||
} else {
|
||||
JS_ReportError(cx, "Error trying to create JSString from data");
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
CCLOGERROR("ResponseText was empty, probably there is a network error!");
|
||||
|
||||
// Return an empty string
|
||||
vp.set(std_string_to_jsval(cx, ""));
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue