언어 설정

Menu
Sites
Language
Get PHP output via Javascript

Hello,

iam new to the Tizen SDK. Iam an owner of a Gear S2 and want to play a bit around.

 

I have a raspberry pi which hosts an webserver. On this webserver there is a php file which outputs "test":
The Php-file simply contains:

echo "test";

Now i want to show this text on the Gear S2 via Javascript. Is it possible to get the output of the php file which lays here:

raspberrypi/test.php

?

 

Thank you very much!

Responses

4 댓글
Marco Buettner

Its a simple XMLHttpRequest ;) You get read the answer of the server with client.response or client.responseText.

function getPHPString() {
    var client = new XMLHttpRequest();
    
    client.open('GET', 'yoururl');
    client.send();
    
    function handle() {
        if(client.readyState !== 4) { // readyState 4 = load complete
            return false;
        }
        
        if(client.status === 200) { // request was successful
            alert("Message from server := " + client.response);
        }
    }
    
    client.onreadystatechange = handle;
}

getPHPString();

dont forget to make your raspberry available from the web or local network

add on the config.xml

<tizen:privilege name="http://tizen.org/privilege/internet"/>

and

<access origin="*" subdomains="true"/>

 

Benjamin Wolf

Hello,

thank you for your answer.

Now there appears an alert. But the alert is empty. It does not contain any text :( I now test in an emulator. Is it okay or does the Emulator not have internet access?

 

my config looks like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="..." xmlns:tizen="..." id="..." version="1.0.0" viewmodes="maximized">
    <tizen:application id="ZGmL4VUUKJ.hello" package="ZGmL4VUUKJ" required_version="2.3.1"/>
    <content src="index.html"/>
    <feature name="..."/>
    <icon src="icon.png"/>
    <name>hello</name>
    <access origin="*" subdomains="true"/>
    <tizen:privilege name="..."/>
    <tizen:profile name="wearable"/>
</widget>

 

Benjamin Wolf

Sorry I was not able to post this with "external links" in it. So i replaced everything that looks like a link with "..." :/

Benjamin Wolf

Okay the debug-Mode show me the Result of the PHP-Script. But why will it not be displayed? :/