Fixed a bug that xhr cross-domain error

This commit is contained in:
VisualSJ 2015-06-17 17:10:31 +08:00 committed by 江龙
parent 05c40b13f9
commit 82c09e8d0c
1 changed files with 7 additions and 4 deletions

View File

@ -104,10 +104,13 @@ var XHRTestLayer = cc.Layer.extend({
// 5 seconds for timeout
xhr.timeout = 5000;
xhr.setRequestHeader("Accept-Encoding","gzip,deflate");
//set arguments with <URL>?xxx=xxx&yyy=yyy
xhr.open("GET", "http://geek.csdn.net/news/detail/33683", true);
if(cc.sys.isNative){
xhr.open("GET", "http://geek.csdn.net/news/detail/33683", true);
xhr.setRequestHeader("Accept-Encoding","gzip,deflate");
}else{
xhr.open("GET", "http://httpbin.org/get?show_env=1", true);
}
xhr.send();
},
@ -127,7 +130,7 @@ var XHRTestLayer = cc.Layer.extend({
ensureLeftAligned(responseLabel);
responseLabel.x = winSize.width / 10 * 3;
responseLabel.y = winSize.height / 2;
var xhr = cc.loader.getXMLHttpRequest();
streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST");