Тема: Вопросы по скрипту
Код скрипта я взяла из примера wialon playground:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Wialon Playground - Create driver</title>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://hst-api.wialon.com/wsdk/script/wialon.js"></script>
</head>
<body>
<style>
.btn {
cursor:pointer;
}
div {
margin-bottom:20px;
}
#log_cont {
background-color: #EEEEEE;
height: 150px;
overflow-y: scroll;
font-size:75%;
}
#log_cont table {
width:100%;
}
</style>
<div id="base">
<div>
Resource: <select id="resource" name="resource"><option value="">-- select resource --</option></select>
<table id="driver_data">
<tbody>
<tr>
<td>Driver name</td>
<td><input type="text" name="n" value="Ken Block"></td>
</tr>
<tr>
<td>Driver description</td>
<td><input type="text" name="ds" value="Cool drifter"></td>
</tr>
<tr>
<td>Driver phone</td>
<td><input type="text" name="p" value=""></td>
</tr>
</tbody>
</table>
<input class="btn" type="submit" id="btn_create_driver" value="Create driver">
</div>
Log:
<div id="log_cont">
<table>
<tbody id="log"></tbody>
</table>
</div>
</div>
<script type="text/javascript">
var createDriver = {
init: function () {
var sess = wialon.core.Session.getInstance();
sess.loadLibrary( "resourceDrivers" );
// flags to specify what kind of data should be returned
var flags = wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Resource.dataFlag.drivers); // 64 bit OR
// Subscribe on resource data
sess.updateDataFlags( // load items to current session
[{type: "type", data: "avl_resource", flags: flags, mode: 0}], // Items specification
function (code){ // updateDataFlags callback
if (code) {
createDriver.log("Error: "+wialon.core.Errors.getErrorText(code));
return; // exit if error code
}
createDriver.res = sess.getItems("avl_resource"); // get loaded 'avl_resource's items
for (var i = 0; i < createDriver.res.length; i++) {
$('#resource').append('<option value="'+ createDriver.res[].getId() +'">'+ createDriver.res[].getName() +'</option>');
}
});
$('#btn_create_driver').click( createDriver.create );
},
create: function (event) {
var res_id = $('#resource').val();
if ( !res_id ) {
alert('Select resource where you want to create driver');
return false;
}
var res = wialon.core.Session.getInstance().getItem(res_id); // get resource by id
if ( !wialon.util.Number.and(res.getUserAccess(), wialon.item.Resource.accessFlag.editDrivers) ) {
createDriver.log('You don\'t have access to edit drivers in ' + res.getName());
return;
}
var $t,
driver = {
"itemId":res_id, // resourceId
"id":0, // item_id
"callMode":"create",
"c":"", // driver code
"ck":0, // image checksum
"ds":"", // description
"n":"", // name
"p":"", // phone
"r":1, // image aspect ratio
"f":0, // flags
"jp":{} // additional fields
}
$('#driver_data input').each(function(){
$t = $(this);
driver[ $t.attr('name') ] = $t.val();
});
res.createDriver( driver, function(code, data) {
createDriver.log('Driver ' + ( (data && typeof data.n != 'undefined') ? "'" + data.n + "'" : '') + ' create result: ' + (code ? 'Error('+code+')' : 'Ok'));
});
},
log: function(msg) {
var $log = $('#log'),
$log_cont = $('#log_cont');
$log.append('<tr><td>' + msg + '</td></tr>');
$log_cont.animate({
scrollTop: $log_cont[0].scrollHeight
}, 300);
}
};
// execute when DOM ready
$(document).ready(function () {
wialon.core.Session.getInstance().initSession("https://hst-api.wialon.com"); // init session
// For more info about how to generate token check
// http://sdk.wialon.com/playground/demo/app_auth_token
wialon.core.Session.getInstance().loginToken("5dce19710a5e26ab8b7b8986cb3c49e58C291791B7F0A7AEB8AFBFCEED7DC03BC48FF5F8", "", // try to login
function (code) { // login callback
if (code){
createDriver.log(wialon.core.Errors.getErrorText(code));
return; // exit if error code
}
createDriver.init(); // when login suceed then run init() function
});
});
</script>
</body>
</html>
Запускаю этот код на своем компе и выдает ошибку:
post.html:101 Uncaught DOMException: Failed to execute 'postMessage' on 'Window': Invalid target origin 'null' in a call to 'postMessage'.
at listener (https://hst-api.wialon.com/wialon/post.html:101:16)