Discord
Login
Community
DARK THEME

Http POST/GET

Hi!

Am I able to make Http(s) POSTs or GETs and parse a JSON, for instance, within the Microstudio ambient, using Javascript?

And, if it is possible to use such Javascript capabilities, if I build an Android apk, those will work the same as on the browser? Still in this line, does the Android builder converts everything to native code, or does it wrap everything as a Html5 and runs it that way?

Thanks!

Am I able to make Http(s) POSTs or GETs and parse a JSON, for instance, within the Microstudio ambient, using Javascript?

This possibility is left open for now, but I cannot guarantee it will remain so. The main goal with the introduction of JavaScript is that you can program your game in JavaScript, using the same feature set and API calls as you would in microScript.

does it wrap everything as a Html5 and runs it that way?

Yes, the Android APK is packaged from the HTML5 export, using Cordova.

That clarifies! Thank you very much!

"This possibility is left open for now, but I cannot guarantee it will remain so."

Sorry to ask... could you please elaborate a little bit further on this section? You mean by that that would be the case that Internet access from whitin the engine is subject to change (privacy/security reasons)?

Thanks again!

I mean the goal is to allow programming your game in JavaScript, using the microStudio APIs ; direct JavaScript support opens up a lot more possibilities (without privacy / security concern as the projects are run on a separate domain - microstudio.io - as the main microStudio site - microstudio.dev -). You may access the DOM, you can make ajax calls, load more JavaScript libs ... If that is what someone needs to do, there are many online services out there allowing them to do that much better: codepen, jsfiddle, codesandbox. I have no reason to block these extra features for now, but I may do so in the future to avoid having projects published in the Explore section which would have nothing to do with the core microStudio spirit and features.

Perfect! Thanks for clarifying!

Maybee some simple AJAX code here? Try:

  $.ajax({
    url: "path_to_php",
       method: "POST",
    data: {"val": 0},
       success: function(data) {
      print(data);
    }
  });

its return '$ is not defined, in file "main" at line'

So question is: how to POST data to server?

UPD:

Also try:
  brk = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {brk = true;}
    }
  } else {brk = true;}

  if(brk) {
    return(false);
  } else {
    http_request.open('POST', path, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.setRequestHeader('Accept-Language', 'en');
    http_request.setRequestHeader('Accept-Charset', 'UTF-8');
    http_request.send(data);
    //return(true);     //This one make next func not  work!
  }

  http_request.onreadystatechange = function() {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        print('Returned: ' + http_request.responseText);
        screen.drawText('Returned: ' + http_request.responseText, 0, 0, 20, '#AAA');
      } else {
        print('Bad status: ' + http_request.status);
        screen.drawText('Bad status: ' + http_request.status, 0, 0, 20, '#AAA');
      }
    } else {
      print('Not ready: ' + http_request.readyState);
      screen.drawText('Not ready: ' + http_request.readyState, 0, 0, 20, '#AAA');
    }
    return(true);
  };

This always return: 'Bad status: 0'
Try export HTML5, set it in my server (wolfdigital), same thing, status: 0 (bad status)...

Project: https://microstudio.io/i/WolfDigital/ajaxtest/

Ok, thru inspector figure it out:

  1. the 'path' in project has 'http://wolfdigital.ru/zNet/zNet.php'
  2. Method POST

But inspector throw errors:

  1. it was try to send to wss://wolfdigital.ru (not http as code require)
  2. inspector recognize GET instead of POST...

So, there is a problem: microengine try to send to WSS instead of HTTP and something make POST AJAX request a GET...

Well, creators :3

I make simple library for network, DOC included.

Its called WD_net (version), right now its WD_net (1.0) (WIP)

Use it for your purposes :)

More libraries will come soon, like objects system, forms, images, buttons (also switched & grouped) and WINDOWS!

All customizable and any have its DOC and default bunch of variables + functionns to work with.

Keep eye on WD_UI (version) (by WolfDigital) and its parts :3

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community