+ Reply to Thread
Results 1 to 5 of 5

Thread: javascript Login

  1. #1
    Join Date
    Nov 2017
    Posts
    8

    Default javascript Login

    Hi to everyone, I have a simple question .
    I am writing an application for xerox machine that interface with efi Rip.
    Xerox app use Javascript, so i need to write my app in javascript. the only problem is that I've never use javascript so I'd like to know how can I re-write for example the "login" funcion (from nodejs to javascript) so I can start develop my app.
    Is there anyone that can tell me how could I do?

  2. #2
    Join Date
    Nov 2017
    Posts
    8

    Default

    I explain better my question.
    the only things I 'd like to know is how rewrite login function from Nodejs to Javascript, because in javascript I have not 'require(https)'..
    I'll post my function:
    ----------
    function login(){

    var loginJson = {
    username: "MyUsername",
    password: "MyPass",
    accessrights: MyapiKey,
    };

    var payload = JSON.stringify(loginJson);

    var len = payload.length;


    var xhr = new XMLHttpRequest();
    var url = 'https://192.168.0.136/live/api/v3/login';
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.setRequestHeader("Content-type", "application/json");
    xhr.setRequestHeader("Content-Length", "len");
    xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
    var json = JSON.parse(xhr.responseText);
    console.log(json);
    }
    };

    xhr.send(payload);
    }
    ----------------------------------------------------------------------
    when i run this function I got an error

  3. #3
    Join Date
    Nov 2017
    Posts
    8

    Default

    Quote Originally Posted by filippo View Post
    I explain better my question.
    the only things I 'd like to know is how rewrite login function from Nodejs to Javascript, because in javascript I have not 'require(https)'..
    I'll post my function:
    ----------
    function login(){

    var loginJson = {
    username: "MyUsername",
    password: "MyPass",
    accessrights: MyapiKey,
    };

    var payload = JSON.stringify(loginJson);

    var len = payload.length;


    var xhr = new XMLHttpRequest();
    var url = 'https://192.168.0.136/live/api/v3/login';
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.setRequestHeader("Content-type", "application/json");
    xhr.setRequestHeader("Content-Length", "len");
    xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
    var json = JSON.parse(xhr.responseText);
    console.log(json);
    }
    };

    xhr.send(payload);
    }
    ----------------------------------------------------------------------
    when i run this function I got an error
    the error I get is "... No 'Access-Control-Allow-Origin' header is present on the requested resource..."....

  4. #4
    Join Date
    Nov 2017
    Posts
    8

    Default

    Just for completeness in this forum.
    Only namcha is try to help me on GithHub( https://github.com/fieryapi/node-js-samples/issues/1 )..
    A special THANKS to him.

  5. #5
    Yusuke_K is offline Fiery Forum Expert Contributor Yusuke_K is on a distinguished path
    Join Date
    Jul 2009
    Posts
    75

    Default

    Hi there,

    Thank you for putting the github link. I'm glad that our colleague was able to help you and we should share the knowledge here as well.

    Best regards,
    Yusuke

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts