[Tizen Application-dev] What is wrong with XmlHttpRequest

Eduard seapost at gmail.com
Wed Oct 24 07:37:50 GMT 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tizen.org/pipermail/application-dev/attachments/20121024/6ae38228/attachment.html>


More information about the Application-dev mailing list