[Tizen Application-dev] What is wrong with XmlHttpRequest

Daehyeon Jung darrenh.jung at samsung.com
Wed Oct 24 08:24:36 GMT 2012


Hi Eduard,

Here's result in my system

Press "send sync"
js/xhr.js (19) :Exception:Error: INVALID_STATE_ERR: DOM Exception 11

Press "sync to google"
js/xhr.js (19) :Exception:Error: INVALID_STATE_ERR: DOM Exception 11

Press "send async"
js/xhr.js (37) :async
js/xhr.js (37) :INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

Press "sync jquery to google"
error:{PP"readyState":4,"responseText":"\n\n\n Error 405 (Method Not Allowed)!! 1\n \n ~~~~~~~~~~~~~

Press "sync jquery"
error:{"readyState":0, "status":0,"statusText":"Error: NETWORK_ERR:XMLHttpRequst Exception 101"}

Those results are same both emulator and simulator. Which SDK Version do you use currently? In my system-SDK 2.0 alpha- has no problem with your application. Make sure internet connection in your emulator(test via browser).


Regards,
Daehyeon

------- Original Message -------
Sender : Eduard<seapost at gmail.com>
Date : 2012-10-24 16:37 (GMT+09:00)
Title : [Tizen Application-dev] What is wrong with XmlHttpRequest

Can you help me 
I can not use XMLHttpRequest on Tizen Emulator.


When I use XMLHttpRequest object in sync mode then I get 
ABORT_ERR: XMLHttpRequest Exception 102: The User aborted a request in synchronous requests


In async mode I can interrupt my send only via timeout


Also i have added <access> tag to config.xml
<access origin="http://172.24.226.21:8125/" subdomains="true"/>
<access origin="http://google.com/" subdomains="true"/>


It is a example


//xhr.js
function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}


function sync(url){
    var xhr = getXmlHttp();
    try{
     xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
 xhr.open('POST', url, false);
     xhr.send(null);
 if(xhr.status == 200) {
   console.alert(xhr.responseText);
 } else {
console.log("xhr.status:"+xhr.status);
 }
    }catch(ex){
      console.log("Exception:"+ex);
    }

}


function async(url){
console.log("async");
var xhr = getXmlHttp();
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.open('POST', url, true);
xhr.onreadystatechange = function() {
  console.log("xhr.readyState:"+xhr.readyState);
  console.log("xhr.status:"+xhr.status);
  console.log("xhr.responseText:"+xhr.responseText);
  if (xhr.readyState == 4) {
  if(xhr.status == 200) {
  console.log("200;"+xhr.responseText);
  }
  }
};
xhr.send(null);
}


function sync_jquery(url, async, data){
$.ajax({
      type : "POST",
    url : url,
contentType: "application/json; charset=utf-8",
       data: JSON.stringify(data), 
    cache : false,
    async : async,
    success : function(data) {
              alert("success:"+data);
            },
    error :  function(e) {
              alert("error:"+JSON.stringify(e));
    }
    });
}


//index.html
<!DOCTYPE html>
<html>
<head>
    <script src="tizen-web-ui-fw/latest/js/jquery.js"></script>
    <script type="text/javascript" src="./js/xhr.js"></script>
</head>


<body>
<button onclick="sync('http://172.24.226.21:8125');">send sync</button>
    <button onclick="sync('http://google.com');">sync to google</button><br>
    <button onclick="async('http://172.24.226.21:8125');">send async</button><br>
    <button onclick="sync_jquery('http://172.24.226.21:8125',false,{type: 'ready'});">sync jquery</button>
    <button onclick="sync_jquery('http://google.com',false,{});">sync jquery to google</button>
</body>
</html>


-- 
Best regards,
 Eduard Serdyuk                          mailto:seapost at gmail.com



Jung, Daehyeon 
Assistant Engineer 
Software R&D Center, Samsung Electronics 
Mobile: +82 (10) 9114-0630


More information about the Application-dev mailing list