I am new to the Tizen SDK. I am an owner of a Gear S2 and want to play a bit around.
I have a raspberry pi which hosts a web server. On this web server, 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
?
I found code like this, but nothing happens with this code:
$.getJSON('http://raspberrypi/test.php', function(e)
{
var contentText = document.querySelector('#content-text');
contentText.innerHTML = e.result;
});
Thank you very much!
use get instead of getJSON
$.get('http://raspberrypi/test.php', function(e)
{
var contentText = document.querySelector('#content-text');
contentText.innerHTML = e.result;
});
getJSON - Loads JSON-encoded data from the server using a GET HTTP request.
get - any format of response it can get, you echoing a string "test" , it is not JSON format
Related
I'm working with a NodeMCU ESP8266 and I want to control my WS2812B with it.
So I made an HTML page with an input range and I want to send the value of the range to my ESP8266 - where the website is hosted - by using AJAX.
I only found tutorials on how to send data from an ESP8266 to a webpage and can't find any tutorials on how to send any info to my ESP8266 from a webpage.
The input looks like this:
<input type=range id="rangeinput">
To send a GET request from your webpage with the value you want to send, you can do something like this (untested, so check; I just typed it in, but you get the idea):
var valueToSend = document.getElementById("rangeinput").value;
var ESP8266URL = ""; // URL of ESP8266 page that handles request goes here
var sendValueRequest = new XMLHttpRequest();
sendValueRequest.open("GET", ESP8266URL + "?value=" + valueToSend, true);
sendValueRequest.onreadystatechange = processReturn;
sendValueRequest.send(null);
function processReturn() {
if (sendValueRequest.readyState == 4 && sendValueRequest.status == 200) {
var return = sendValueRequest.responseText;
// Do something (or nothing) with what the server sent back
}
}
You will have to handle the GET request on the ESP8266. How to do that depends on how the webserver on your ESP8266 is set up.
I'm trying to display this code with JSONView but won't display when calling the data from inside the api callback function, but will display non api data when placed outside the callback.
// Call FreeGeoIP API to get browser IP address
$.getJSON('https://freegeoip.net/json/', function(data) {
var ipaddress = data.ip;
// Get browser language
var language = window.navigator.language;
// Get software
var software = window.navigator.appVersion;
var regExp = /\(([^)]+)\)/;
software = regExp.exec(software)[1];
// Add data to obj
var obj = {
'ipaddress': ipaddress,
'language': language,
'software': software
};
// Write obj to document
$('body').html(JSON.stringify(obj));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
JSONView extension or any other extensions in the Chrome browser needs permission to access file URLs if it is accessing files from your local system.
To allow:-
Visit chrome://extensions/
Click on Details button of the Extension card
Switch ON the Allow access to file URLs
JSONView or any other json formatter detects if you are viewing json on basis on contentType of the document loaded (as set on http header).
Since you must be running this code on client side (browser) the contentType is set to text/html .
For the plugin to correctly format the json, it must know that what you're looking at is indeed json and it does so by reading contentType header.
That is why fetching json via this script shows json as text in body attribute but not picked up by the plugin.
I have code in place where I'm using EO.WebBrowser to get the html from a page using the EO.WebView Request:
var cookie = new EO.WebBrowser.Cookie("cookie", "value");
cookie.Path = path;
cookie.Domain = domain;
var options = new BrowserOptions();
options.EnableWebSecurity = false;
Runtime.SetDefaultOptions(options);
var request = new Request(url);
request.Cookies.Add(cookie);
webView.LoadRequestAndWait(request);
Finally I use the following to get the HTML I need:
webView.GetDOMWindow().document.body.outerHTML
My issue is that this is very slow and although I can get it to run it locally, I can not get it to run on Azure server code. Is there a way to do the same thing using HttpWebRequest?
You can use JavaScript:
var data = (string)webView.EvalScript("document.body.outerHTML");
No, HttpWebRequest (and other similar "get me HTML response") methods will only give you HTML itself and will not run JavaScript on the page.
For server side processing of dynamic HTML consider using proper headless internet browser? instead of trying to convince regular IE to work correctly without UI.
the eo.webbrowser runs multi-process like chrome and unsupported by many cloud service environment.
just use WebClient or HttpWebRequest or RestSharp or something like that can do http requests to get the response html.
I am new to jQuery and JavaScript. I am trying to read the content of a .doc file and display it in a textarea.
var url = "D:\\way2Jobs\\way2jobz\\WebContent\\pages\\Resumes\\";
var firstName = $("#first").val();
var extn=".doc";
jQuery.ajax({
url : url+firstName+extn,
dataType : "doc",
success : function(data){
alert(firstName);
document.getElementById("candResume").innerHTML = data;
}
});
You just can't (thanks god) make an ajax request to your local filesystem. It's a safety restriction and you can't bypass this.
1 - You have to at least use a webserver like apache
2 - You never will sucessfuly make a request to D:\
3 - You CAN request a DOC file and process it using javascript. But it's not that easy because DOC file isn't a plain text and javascript was not made for it. Maybe it's easier for you to do it using a server side language such as PHP or JAVA or even NodeJS if you are familiar with javascript.
I'm used to selecting, opening and reading a text file (CSV, JSON) from my local directory. I now have access to our data feeds online but don't know how to do the same thing with a URL instead of a local file.
For a local file I simply use something like this:
var myFile = File.openDialog();
myFile.open();
myFile.read();
Is there a way to do this with a feed from a URL in javascript for AE?
Here is one of the feeds: feeds.nfl.com/feeds-rs/schedules.json
No need to save file, just one line do the trick =)
data = JSON.parse(system.callSystem('curl -s "https://path_to_json"'));
I think in After Effects the easiest way is to do a system call.
The Socket object from ExtendScript is complicated. Look at GetURLs.jsx by Rorohiko.
You need to allow your script to access the network. See this stackoverflow
# Mac Osx
var curlcmd = "curl feeds.nfl.com/feeds-rs/schedules.json > ~/Desktop/test/schedules.json";
var stdout = system.callSystem(curlcmd);
$.writeln(stdout);
var file = File("~/Desktop/test/schedules.json");
file.open();
var content = file.read();
file.close();
$.writeln(content);