1

Use Remote API in JavaScript(Vue.js)

Тема: Use Remote API in JavaScript(Vue.js)

i want to use the Remote API in JavaScript(Vue.js specifically)
i tried with the below URL
http://********/wialon/ajax.html?sid=ca81753899425965bc078c1d3df674d4&svc=core/search_item&params={"id":16174,"flags":1}
but the problem is i got this error in my browser
Failed to load http://********/wialon/ajax.html?sid=ca81753899425965bc078c1d3df674d4&svc=core/search_item&params={"id":16174,"flags":1}: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

i tried to add 'Access-Control-Allow-Origin' header to my request but nothing happened.

Could you please help me this issue.

Thanks.

2

Use Remote API in JavaScript(Vue.js)

Re: Use Remote API in JavaScript(Vue.js)

Hello

Direct request to Wialon from browser won't  work (because of 'Access-Control-Allow-Origin' header). You can use one of existing libraries like Wialon SDK JS or https://github.com/wialon/wialonjs-api . Or develop your own)

BTW to communicate with server Wialon use iframe and postMessage. You can check it here https://github.com/wialon/wialonjs-api/ … Request.js

3

Use Remote API in JavaScript(Vue.js)

(28/02/2018 08:36:38 отредактировано kaippally)

Re: Use Remote API in JavaScript(Vue.js)

Direct Access to Wialon works if you post queries by the following method. You will need Jquery.

var server_error = [];


server_error[0] = "Successful operation";
server_error[1] = "Invalid session";
server_error[2] = "Invalid service name";
server_error[3] = "Invalid result";
server_error[4] = "Invalid input";
server_error[5] = "Error performing request";
server_error[6] = "Unknown error";
server_error[7] = "Access denied";
server_error[8] = "Invalid user name or password";
server_error[9] = "Authorization server is unavailable";
server_error[10] = "Reached limit of concurrent requests";
server_error[1001] = "No messages for selected interval";
server_error[1002] = "Item with such unique property already exists";
server_error[1003] = "Only one request is allowed at the moment";

var sess = wialon.core.Session.getInstance(), sid = sess.getId(), hostUrl = sess.getBaseUrl();

function syscom(svc, params, variable, fn) {
    $.ajax({
            timeout: 5000,
            url: hostUrl + "/wialon/ajax.html?sid=" + sid,
            data: {
                svc: svc,
                params: JSON.stringify(params)
            },
            type: 'post',
            dataType: 'jsonp',
            jsonp: 'callback',
            success: function(d) {
                window[variable] = d
                console.log(d)
                if (d.error) {
                    console.log(server_error[d.error]);
                }
                if (d.error) {

                 console.log(server_error[d.error])
             


                    return
                }

                if (typeof fn == 'function') fn();

            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(errorThrown);
                console.log(textStatus);
            }
        })

}

Your query

http://********/wialon/ajax.html?sid=ca81753899425965bc078c1d3df674d4&svc=core/search_item&params={"id":16174,"flags":1}

would be run like this.


syscom("core/search_item", {
        "id": 16174,
        "flags": 1
    }, 'sysquery', function() {
        console.log(sysquery)
    })

Please note:  that this method is limited to queries with a maximum string length of 2083 characters.

Have fun

Cheers

Nishad Hussain Kaippally
Implementation Specialist, Middle East, Gurtam

"Computer science is no more about computers than astronomy is about telescopes."
4

Use Remote API in JavaScript(Vue.js)

Re: Use Remote API in JavaScript(Vue.js)

perfect