언어 설정

Menu
Sites
Language
How to get content from webpage without using DownloadManager ?

I'm learning Web Developement for Tizen. Is there any way to  get content from webpage without using DownloadManager ? I want to get that as string, I think when I use DownloadManager, my app will create notification everytime I retrieve content from webpage, I dont like that. 

답변 바로가기

Responses

4 댓글
Iqbal Hossain

Hi~ 
You can use Ajax request to get the data from server in String/JSON form. 

Code like this 

function getServerData() {
        'use strict';

        console.log( "ready!" );
          $.ajax({
            type: "GET",
            url: "http://rest-service.guides.spring.io/greeting", // Server URL
            success: function (data) {
                  console.log(JSON.stringify(data)); // Server data in String format
                  console.log(data); // Server data in JSON format
             }
       });
    }

You also need to give permission for internet and allow domains in your config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/XXXX" version="1.0.0" viewmodes="maximized">
    <tizen:application id="qVBTv1uptg.XXXX" package="qVBTv1uptg" required_version="2.3.1"/>
    <content src="index.html"/>
    <access origin="http://spring.io" subdomains="true"></access>
          <access origin="*" subdomains="true"></access>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>XXXX</name>
    <tizen:privilege name="http://tizen.org/privilege/internet"/>
    <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
    <tizen:profile name="wearable"/>
</widget>

Hope this will help you. 

Thanks.

Dinh Hao

Do I need to set "Content Security Policy" ? It show error "Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'"." everytime this code execute.

Mark as answer
Iqbal Hossain

May be you have something in your code like this:

<button onclick="myFunction()">Click me</button>

In a nutshell this is not allowed. Change this to the following and it will work:

index.html: 
<button id="myButton">Click me</button>
<script src="myScripts.js"></script>

main.js:
document.getElementById("myButton").addEventListener("click", myFunction);

function myFunction(){
    console.log('myFunction is called');
}

 

Content Security Policy does not allow inline javascript. So you have to put your javascript in a .js file and include it to your html.

Dinh Hao

Thank you, it worked like a charm now :)