Javascript ajax请求使用$,但不使用$
我有一些jQuery,可以获取数据并执行回调:Javascript ajax请求使用$,但不使用$,javascript,jquery,ajax,angularjs,http-headers,Javascript,Jquery,Ajax,Angularjs,Http Headers,我有一些jQuery,可以获取数据并执行回调: $(function(){ $.ajax({ type: 'POST', url: 'http://flash-cast-hrd.appspot.com/api/sonar/sync', data: { source: 5, auth: 'JXEI....DHA2J' }, success: displayData }); }); 我正试图从我的角度控制器发出同样的请求,
$(function(){
$.ajax({
type: 'POST',
url: 'http://flash-cast-hrd.appspot.com/api/sonar/sync',
data: {
source: 5,
auth: 'JXEI....DHA2J'
},
success: displayData
});
});
我正试图从我的角度控制器发出同样的请求,在这里我有一个作用域上的方法
$scope.init = function(){
$http.post('http://flash-cast-hrd.appspot.com/api/sonar/sync', {
source: 5,
auth: 'JXEI....DHA2J'
})
.success(function(data){
console.log(data);
})
.error(function(error){
console.log('Error is: ' + error);
});
};
然后在视图中调用它:
<div ng-init="init()"></div>
如何使$http.post请求工作?问题是由于跨域访问,您可以通过在服务器上设置proxypass来解决,并且您的请求还需要包含访问控制允许标头。此XMLHttpRequest错误的可能重复可以通过在服务器上部署来解决,在部署到服务器后尝试运行它,希望它将工作访问控制允许从服务器端处理Origintry
OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync 405 (Method Not Allowed) angular.js:8021
OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. angular.js:8021
XMLHttpRequest cannot load http://flash-cast-hrd.appspot.com/api/sonar/sync. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. :8000/routes:1
Error is: