0
が定義されていないと言う::キャッチされていないにReferenceError:make_basic_authは、タイトルのよう
を「捕捉されないにReferenceErrorをmake_basic_authが定義されていない」私はbluethooth経由でアプリに接続されているセンサーを持っています。アプリはデータをクラウドサービスに送信します。私は、json形式のデータを含むクラウドサービスからのリンクを取得し、そこからデータを取得する必要があります。
make_basic_authは、私のGET要求を認証する機能です。
私は新しいと私は間違っていた手がかりを持っていない。
<html>
\t <head>
\t \t <title>Test</title>
\t \t <script src="jquery-3.2.1.min.js"></script>
\t \t <script src="Base64Toolkit.js"></script>
\t </head>
\t \t <body>
\t \t <button onclick="myFunctionPost()">Post</button>
\t \t <div id="result" style="color:red"></div>
\t \t <script>
\t \t \t function make_base_auth(user, password) {
\t \t \t var tok = user + ':' + pass;
\t \t \t var hash = Base64.encode(tok);
\t \t \t return "Basic " + hash;
\t \t \t }
\t \t \t var auth = make_basic_auth('myUSERNAME','myPASSWORD');
\t \t \t var url = 'myURL';
\t \t \t // RAW
\t \t \t xml = new XMLHttpRequest();
\t \t \t xml.setRequestHeader('Authorization', auth);
\t \t \t xml.open('GET',url)
\t \t \t // ExtJS
\t \t \t Ext.Ajax.request({
\t \t \t url : url,
\t \t \t method : 'GET',
\t \t \t headers : { Authorization : auth }
\t \t \t });
\t \t \t // jQuery
\t \t \t $.ajax({
\t \t \t url : url,
\t \t \t method : 'GET',
\t \t \t beforeSend : function(req) {
\t \t \t req.setRequestHeader('Authorization', auth);
\t \t \t }
\t \t \t });
\t \t \t function myFunctionPost() {
\t \t \t \t var getJSON = function(url) {
\t \t \t \t \t return new Promise(function(resolve, reject) {
\t \t \t \t \t \t var xhr = new XMLHttpRequest();
\t \t \t \t \t \t xhr.open('get', url, true);
\t \t \t \t \t \t xhr.responseType = 'json';
\t \t \t \t \t \t xhr.onload = function() {
\t \t \t \t \t \t \t var status = xhr.status;
\t \t \t \t \t \t \t if (status == 200) {
\t \t \t \t \t \t \t \t resolve(xhr.response);
\t \t \t \t \t \t \t } else {
\t \t \t \t \t \t \t \t reject(status);
\t \t \t \t \t \t \t }
\t \t \t \t \t \t };
\t \t \t \t \t \t xhr.withCredentials = true;
\t \t \t \t \t \t xhr.send();
\t \t \t \t \t });
\t \t \t \t };
\t \t \t \t getJSON('myURL').then(function(data) {
\t \t \t \t alert('Your Json result is: ' + data.result); //you can comment this, i used it to debug
\t \t \t \t result.innerText = data.result; //display the result in an HTML element
\t \t \t \t }, function(status) { //error detection....
\t \t \t \t alert('Something went wrong.');
\t \t \t \t });
\t \t \t }
\t \t </script>
\t \t </body>
</html>