简体   繁体   English

Angular SyntaxError:缺少; 在声明之前

[英]Angular SyntaxError: missing ; before statement

If I run this.... 如果我跑这个....

var url = "http://api.ean.com/ean-services/rs/hotel/v3/list?cid=xxx&apiKey=xxx&minorRev=30&currencyCode=AUD";
        $http.jsonp(url)
            .then(function(mycallback){
                $scope.md = mycallback;
                var mydata = mycallback.data; 
                console.log(mydata);            
        });

I get: this error SyntaxError: missing ; 我得到:这个错误SyntaxError:missing; before statement 在声明之前

If I change it to get: 如果我改变它得到:

 var url = "http://api.ean.com/ean-services/rs/hotel/v3/list?cid=xxx&apiKey=xxx&minorRev=30&currencyCode=AUD";
        $http.get(url)
            .then(function(mycallback){
                $scope.md = mycallback;
                var mydata = mycallback.data; 
                console.log(mydata);            
        });

I get this error SyntaxError:JSON.parse.unexpected end of data at line 1 column 1 of the json data 我得到此错误SyntaxError:JSON.parse.unexpected json数据的第1行第1列的数据结束

If I put callback=JSON_CALLBACK at the end it makes no difference. 如果我把callback = JSON_CALLBACK放在最后它没有任何区别。 Either which way I can't console.log this endpoint. 无论哪种方式我都无法console.log这个端点。 So stressful. 压力很大。

I have tried other endpoints such as these and these work correctly var url = ' http://jsonplaceholder.typicode.com/posts/1 '; 我已经尝试过其他端点,例如这些端点,这些端点正常工作var url =' http://jsonplaceholder.typicode.com/posts/1 '; var url = " http://www.w3schools.com/angular/customers.php "; var url =“ http://www.w3schools.com/angular/customers.php ”;

在此输入图像描述

它呼叫成功并在右侧重新开始

Please try encoding the URI before passing it to the request. 请在将URI传递给请求之前尝试对URI进行编码。 This seems to be the only issue here as we need to encode special characters inside your query string here. 这似乎是唯一的问题,因为我们需要在这里对查询字符串中的特殊字符进行编码。

url = encodeURI(url)

var url = 'url' + '?callback=JSON_CALLBACK'这将解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM