语言

Menu
Sites
Language
problem with developping on the tizen device

Hi every body

this code that is  a part of my applicationn, don't work on the tizen device while it work normally on the tizen simultor ... can any one have a look and tell me why !! if it's a problem with the balise form or with the dom parser ! can anyone tell me how to solve it ?

thx

 

 







<!DOCTYPE html>

<head>
                                           

</head>
<body>
<div id="result">
</div>
<div align="center">
<form  name="myForm">

<button  type="submit">go</button>
</form>  
</div>

<script>
    //var doc;
	var xhr = new XMLHttpRequest();
	xhr.open('GET', 'http://www.sntri.com.tn/html_ar/result_tarif_horaire_sntri.php', true);
	//xhr.setRequestHeader('Origin', 'www.sntri.com.tn');
	//xhr.setRequestHeader('Allow-Control-Allow-Origin', '*');
	xhr.send();
	xhr.onreadystatechange = function() {
		if(4 === xhr.readyState) {
			if(200 === xhr.status) {
				var parser = new DOMParser();
				var doc = parser.parseFromString(xhr.responseText, 'text/html');
				var myForm = document.forms.myForm;
				//console.log(doc);
				var selectDep = doc.getElementsByName('code_arret_dep')[0];
				var selectArr = doc.getElementsByName('code_arret_arr')[0];
				doc.getElementBy
				//console.log(select);	
				myForm.appendChild(selectDep);	
				myForm.appendChild(selectArr);
				//console.log(xhr.responseText);
	
				myForm.onsubmit = function(e) {
					e.preventDefault();
					var xhr = new XMLHttpRequest();
					xhr.open('POST', 'http://www.sntri.com.tn/html_ar/result_tarif_horaire_sntri.php', true);
					xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xhr.send('code_arret_dep='+selectDep.value+'&code_arret_arr='+selectArr.value);
					
					xhr.onreadystatechange = function() {
						if(4 === xhr.readyState) {
							if(200 === xhr.status) {
								var parser = new DOMParser();
								var doc = parser.parseFromString(xhr.responseText, 'text/html');
								var result = document.getElementById('result');
								var tablex = doc.getElementById('tablex');
								//console.log(doc);
								result.appendChild(tablex);
								//console.log(xhr.responseText);
							}
						}
					}
					
					console.log(selectDep.value);
					console.log(selectArr.value);
				}
			}
		}
	};
</script>
</body>

</html>

 

响应

4 回复
Seoghyun Kang

Hello,

 

Did you add the following code at config.xml?

If you want to access to external server, you need to add it.

 

<tizen:privilege name="http://tizen.org/privilege/internet"/>
<access origin="*" subdomains="true"></access>

 

Please refer it.

Thanks.

wassim ben hamida

yes

wassim ben hamida

yes i have add it but it doesn't work yet :'(

 

AVSukhov

Hello,

Looks like Tizen does not support "text/html" mime-type natively.

add following function to your script:

(function(DOMParser) {  
    "use strict";  
    var DOMParser_proto = DOMParser.prototype  
      , real_parseFromString = DOMParser_proto.parseFromString;

    // Firefox/Opera/IE throw errors on unsupported types  
    try {  
        // WebKit returns null on unsupported types  
        if ((new DOMParser).parseFromString("", "text/html")) {  
            // text/html parsing is natively supported  
            return;  
        }  
    } catch (ex) {}  

    DOMParser_proto.parseFromString = function(markup, type) {  
        if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {  
            var doc = document.implementation.createHTMLDocument("")
              , doc_elt = doc.documentElement
              , first_elt;

            doc_elt.innerHTML = markup;
            first_elt = doc_elt.firstElementChild;

            if (doc_elt.childElementCount === 1
                && first_elt.localName.toLowerCase() === "html") {  
                doc.replaceChild(first_elt, doc_elt);  
            }  

            return doc;  
        } else {  
            return real_parseFromString.apply(this, arguments);  
        }  
    };  
}(DOMParser));

from here:

https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#DOMParser_HTML_extension_for_other_brow