언어 설정

Menu
Sites
Language
XMLHttpRequest.responseType "json" is not supported

Hello,
I am new in Tizen.
I am trying to send a XMLHttpRequest to server to create a "whataApp" account by using coseme.js.

I copied the following XMLHttpRequest code from coseme.js for WhatsApp - 
 

var URL = 'https://v.whatsapp.net/v2/' +
                operation + '?' + CoSeMe.utils.urlencode(params);
      logger.log('Request:', URL);

      // Perform the query
     var xhr = new XMLHttpRequest({mozSystem: true});
   xhr.onload = function() {
  logger.log(this.response);
  onready && onready.call(this, this.response);
   };
   xhr.onerror = onerror;
   xhr.open('GET', URL,true);
   xhr.overrideMimeType('json');
   xhr.responseType = 'json';
   xhr.setRequestHeader('User-Agent', CoSeMe.config.tokenData['u']);
   xhr.setRequestHeader('Accept', 'text/json');
   xhr.send();

 

but it shows the following Error :
  XMLHttpRequest.responseType "json" is not supported.
  
Is responseType json is not supported in Tizen? If supported, then how can I active this for my application?

Edited by: Emrajul Islam on 29 6월, 2015

Responses

4 댓글
Prajith Premanandan
First check whether your code is working in Tizen Browser If its working in browser then may be its a External resources access issue
Emrajul Islam

Hello

Thanks for your reply. We checked following code in Tizen Device to check responseType="json"

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen basic template generated by Tizen Web IDE"/>

    <title>'xhr.responseType = 'json'' demo</title>

    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script src="js/main.js"></script>
</head>

<body>
  <header>
    <hgroup>
      <h1>XMLHttpRequest.responseType "json" test in Tizen app</h1>
      <h2>An empty template of tizen</h2>
    </hgroup>
  </header>

  <style>
    #support { border: 1px solid; padding: 1em; }
 .fail { background: pink; border-color: red; padding: 1em; }
 .pass { background: lightgreen; border-color: #468847; padding: 1em; }
</style>
<p>This document loads a raw JSON resource using Ajax, avoiding the explicit parsing step by setting <code>xhr.responseType = 'json'</code>. It then displays (part of) the data in an alert box.
<p>See <a href=/notes/xhr-responsetype-json>Loading JSON-formatted data with Ajax and <code>responseType='json'</code></a> for more information.
<p id=support>Pending…</p>
</a>
<script>
 (function() {

  var element = document.getElementById('support');

  var notSupported = function() {
   element.innerHTML = 'Your browser doesn’t seem to support <code>xhr.responseType="json"</code> yet. :(';
   element.className = 'fail';
  };

  var supported = function() {
   element.innerHTML = 'Your browser seems to support <code>xhr.responseType="json"</code>. Hurray! You should see an alert box with your public IP address, which was loaded as JSON via Ajax.';
   element.className = 'pass';
  };

  var getJSON = function(url, successHandler, errorHandler) {
   if (typeof XMLHttpRequest == 'undefined') {
    return notSupported();
   }
   var xhr = new XMLHttpRequest();
   xhr.open('get', url, true);
   xhr.responseType = 'json';
   xhr.onload = function() {
    var status = xhr.status;
    if (status == 200) {
     successHandler && successHandler(xhr.response);
    } else {
     errorHandler && errorHandler(status);
    }
   };
   xhr.send();
  };

  // load a non-JSON resource
  getJSON('https://mathiasbynens.be/demo/ip', function(data) {
   if (typeof data == 'string') {
    notSupported();
   } else {
    supported();
    alert('Your public IP address is: ' + data.ip);
   }
  });

 }());
</script>   
</body>
</html>

 After check we found error "Your browser doesn’t seem to support xhr.responseType="json yet.". In web simulator its working fine.

colin Rao

Hi, 

I think 

xhr.setRequestHeader('Accept', 'text/json');

is same with the responseType = 'json'

Just to remove xhr.responseType = 'json', and try the sample code to check whether your code is ok or not.

AVSukhov

Hello,

Try remove xhr.responseType = 'json' and use following:

var xml = new XMLHttpRequest();
 xml.open("GET", url, true);

 xml.onreadystatechange = function() {
   if (xml.readyState != 4)  { return; }

   var serverResponse = JSON.parse(xml.responseText);
 };

 xml.send(null);