Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从$http服务/控制器到JSONP_Javascript_Angularjs_Node.js_Ionic_Jsonp - Fatal编程技术网

Javascript 从$http服务/控制器到JSONP

Javascript 从$http服务/控制器到JSONP,javascript,angularjs,node.js,ionic,jsonp,Javascript,Angularjs,Node.js,Ionic,Jsonp,由于我的跨域错误,我正在尝试将$http调用转换为JSONP调用 请求的服务器上不存在“Access Control Allow Origin”标头 资源因此,不允许原产地 进入 我是一个初学者,从我的控制器中提取了GET服务,我正在努力根据Angular文档找到将$http更改为$http.jsonpurl的位置 这是我的service.js: 和controller.js: JSONP可以让您执行cors请求,但这并不意味着您将能够得到正确的响应 JSONP要求您将JSON响应封装到Java

由于我的跨域错误,我正在尝试将$http调用转换为JSONP调用

请求的服务器上不存在“Access Control Allow Origin”标头 资源因此,不允许原产地 进入

我是一个初学者,从我的控制器中提取了GET服务,我正在努力根据Angular文档找到将$http更改为$http.jsonpurl的位置

这是我的service.js:

和controller.js:


JSONP可以让您执行cors请求,但这并不意味着您将能够得到正确的响应

JSONP要求您将JSON响应封装到Javascript函数调用中。 当您对请求执行JSONP时,查询字符串将设置一个名为 “回调”,它将告诉服务器如何包装JSON响应

服务器应该使用请求字符串中的回调参数来设置 作出相应的答复

因此,答案应该是肯定的

callback([ {“access_token”: “asdfsd”, “expires”: “86400" ,"type" : "bearer"}
]);
在角度上,它看起来像

angular.callbacks._0([ {“access_token”: “asdfsd”, “expires”: “86400" ,“type” :
“bearer”} ]);
但是,为了了解如何进行jsonp调用,请更改代码

return $http (
      {
        method: 'GET',
        cache: true,
        crossDomain: true,
        dataType: 'jsonp',
        url: 'https://www.kimonolabs.com/api/[key]?callback=JSON_CALLBACK',
        headers: {
              'authorization': 'Bearer [auth]'
        }
      });

angular.callbacks._0([ {“access_token”: “asdfsd”, “expires”: “86400" ,“type” :
“bearer”} ]);
return $http (
      {
        method: 'GET',
        cache: true,
        crossDomain: true,
        dataType: 'jsonp',
        url: 'https://www.kimonolabs.com/api/[key]?callback=JSON_CALLBACK',
        headers: {
              'authorization': 'Bearer [auth]'
        }
      });
 return $http.jsonp('https://www.kimonolabs.com/api/[key]?callback=JSON_CALLBACK',{
headers: {
              'authorization': 'Bearer [auth]'
        }
});