Get and Post data

From SpinetiX Support Wiki

Jump to: navigation, search

Introduction

Whenever you need the HMP to get some data from a web server and / or to post some data to it, you need to write the JavaScript code to implement this, using the get and / or post methods described below.

Possible usage scenarios:

  • request some database stored informations from a web server (an HTTP page that queries a database and returns the result) and display these on the screen;
  • display an interactive subscription form on the screen where the user can enter some texts (for instance: first name, last name, email address etc. ) and send the submitted texts to a web server for further processing / actions.
  • communicate with a web service (SOAP, REST etc.);
  • communicate with a website that uses FORM based authentication, which is not directly supported on the HMP (see web server page for more details) and does not require storing cookies (as this is not supported by the HMP before 4.1.0 release).

What about using PHP for this?

  • The support for PHP scripting within projects has been removed, in favor of JavaScript, therefore this approach is strongly not recommended.
  • The cURL module is not supported and cannot be loaded on the player in any way.
  • The OpenSSL and SOAP extensions are both present / enabled, but only the former is loaded by default.

Get data

To request a remote resource you can use:

Post data

To post some data to a remote resource you can either use the postURL() method or one of the jSignage AJAX methods: .ajax() or .post().

The postURL() method is defined in the SVGGlobal interface, as following:

void postURL(in DOMString iri, in DOMString data, in AsyncStatusCallback callback, in DOMString type, in DOMString encoding);

For instance, to post an XML message to a SOAP web service, you could write something like this:

var xmlToSend = "<?xml version='1.0' encoding='utf-8'?>"; 
xmlToSend += "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'";
// ... the rest of the message
xmlToSend += "</soapenv:Envelope>";

postURL(uri,xmlToSend,callback,'text/xml');

function callback(xml)  {
  alert(xml.content);
}
  • Note that the only drawback of using this method is that you cannot set any (custom) HTTP headers, if your SOAP web service might require such headers.
This page was last modified on 9 January 2017, at 19:59.