0
정의되지 않은 : :catch되지 않은 오류 ReferenceError가 : 제목 말한다처럼 make_basic_auth는
나는 bluethooth를 통해 응용 프로그램에 연결되어있는 센서가 "catch되지 않은 ReferenceError가 make_basic_auth가 정의되어 있지 않습니다." 앱이 데이터를 클라우드 서비스로 보냅니다. json 형식의 데이터가 포함 된 클라우드 서비스의 링크가 있는데 그 데이터를 가져와야합니다.
make_basic_auth은 내 GET 요청을 인증하는 기능입니다.
Im 신제품과 나는 내가하지 않았던 단서를 가지고 있지 않다.
<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>