언어 설정

Menu
Sites
Language
I cannot use ajax in Tizen wearable.

Hi

I want to get the weather information to use ajax in my Tizen wearable application, but it do not work.

The error message is that

 

Setting the debugging URL... > Fail
Error occurred at the below step.
 `Setting the debugging URL...`
 (Return Code:1102)Cannot read response content.

 

I already enrollment access '*' and 'true', but it didn't work too.

Code:

 

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Weather API</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="js/jquery.min.js"></script>
<script>

    jQuery(document).ready(function($) {
         
         $.ajax({
        
        url :  "http:"+"//api.openweathermap.org/data/2.5/weather?q=seoul&APPID=c3c02a7bf6a05a0e88d10ec50dcf6efb",
        dataType : "json",
    
        success : function(parsed_json) {

        var weather = parsed_json.weather;
        
        var weather_s = "<p>Weather:" +weather[0].main+"</p>"; 
        weather_s += "<p> Info: " + weather[0].description+"</p>";
        weather_s += "<img src=\"http:"+"//openweathermap.org/img/w/" + weather[0].icon + ".png\">"; 
        $("#weatherinfo").append(weather_s);

        var temp = parsed_json.main;
        var temp_s = "<p>Temp:" + Math.round(10*(temp.temp -273.15))/10 +"℃"+"</p>";
        $("#weatherinfo").append(temp_s);
        },
        error: function(e) {
           alert("Error");
          }
       });
    });

    </script>
</head>
<body> 
 
<div data-role="page">
 
    <div data-role="header">
    </div><!-- /header -->
 
    <div data-role="content">    
        <div id="locationinfo">
        </div>
        <div id="observinfo">
        </div>
        <div id="weatherinfo">
        </div>
    </div><!-- /content -->
</div><!-- /page -->
 
</body>
</html>

   

Plz help me. thanks.

답변 바로가기

Responses

16 댓글
Stephan König

You need to add "http://tizen.org/privilege/internet" under priviliges in config.xml to get access to internet.

SeungHoon Woo

Thanks to your reply, but I already tried it , and it didn't work... 

colin Rao

what's the error message?

SeungHoon Woo

Thanks to your reply.
When I run the app in debug mode then the error message is

'Launching weatherTest' has encountered a problem.
Setting the debugging URL... > Fail

Setting the debugging URL... > Fail
Error occurred at the below step.
'Setting the debugging URL...'
(Return Code:1102)Cannot read response content.

like this.

AVSukhov

Hello,

This is Launch (debug) error, not ajax request releated problem.

AVSukhov

Launch you app in "normal" mode and add following code to error property:

error:function (e) {

alert(e);

}

and and report what error message.

SeungHoon Woo

Thanks to your reply.

I try to that way and the alert just show that

[object Object]
           OK

 

I don't know what does it mean..

AVSukhov

try to use alert(JSON.stringify(e))

SeungHoon Woo

It show that error code:

 

{"readyState":0 , "responseText":"", "status":0, "statusText":"error"}

Marco Buettner

I think the Chrome Path in the SDK preferences are not correct.

SeungHoon Woo

Thanks to your reply.

You means that Windows > Preferences > Tizen SDK > Web > Chrome ?

I check the location of Chrome.exe but it is correct path.

If not, How can I check the Chrome Path?

SeungHoon Woo

Additionally, the code is running successful when I execute "index.html" in chrome web browser.

Stephan König

Try to setup a new project with template "basic/jQuery template".

Add your code to js/main.js like:

$(window).load(function(){
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });
	
	
	$('.contents').on("click", function(){
		$('#textbox').html($('#textbox').html() == "Basic" ? "Sample" : "Basic");		
			         
	         $.ajax({
		        
		        url :  "http://api.openweathermap.org/data/2.5/weather?q=seoul",
		        dataType : "json",
		    
		        success : function(parsed_json) {
		
		        var weather = parsed_json.weather;
		        
		        var weather_s = "<p>Weather:" +weather[0].main+"</p>"; 
		        weather_s += "<p> Info: " + weather[0].description+"</p>";
		        weather_s += "<img src=\"http:"+"//openweathermap.org/img/w/" + weather[0].icon + ".png\">"; 
		        $("#weatherinfo").append(weather_s);
		
		        var temp = parsed_json.main;
		        var temp_s = "<p>Temp:" + Math.round(10*(temp.temp -273.15))/10 +"℃"+"</p>";
		        $("#weatherinfo").append(temp_s);
	        },
	        error: function(e) {
	           alert("Error");
	          }
	       });
	    });
		
});

Also add priviliges and policy settings as needed.

Then you can trigger your request with a tap on the screen which works fine for me on a Gear S device.
I think it's not a good idea to add your code direct into the index.html. Better you use some of the templates and just change it to your needs to avoid unexpected behaviour ;)

SeungHoon Woo

Hi
I'm so happy for your help, but It doesn't run on my gear S device...

It shows same error message like old code..


If there are any conditions to check except policy and priviliges?

Mark as answer
Stephan König

Hi,

can you start your app with debugger (F11) and tell what the network tab tells you about your request? (you may have to press F5 to see your request)
If the debugger didn't work for you, you can also open a command promt and enter:

  • sdb dlog ConsoleMessage (this will show all js console.log prints)
  • sdb dlog WPROXY (this will show all web requests with status, response, error...)

Maybe you can get some more info about the problem this way.
Also can you tell for which wearbale you try to develop this app? (model, firmware...)

 

I also uploaded a small testprogramm for you (http://www.filedropper.com/weathertest).
Just import and try if it works for you. Works for me on a Gear S.

SeungHoon Woo

Hi,
It works perfectly without any problem on my Gear S!

I try to analyze your sample code. 
Thank u ! Have a nice day XD