一切都很好 - 当我发送这样的请求时:
function toServer2(url, type, data, success) {
var XHR = ("onload" in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;
var xhr = new XHR();
xhr.open(type, url, true);
xhr.send(data);} // data = "{'name': 'Ben', count: 12}"
415回复 - 当我发送这样的请求时:
function toServer2(url, type, data, success) {
var XHR = ("onload" in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;
var xhr = new XHR();
xhr.open(type, url, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(data);} // data = "{'name': 'Ben', count: 12}"
否'访问控制 - 允许 - 来源' - 当我发送这样的请求时:
factory.get = function(idLocation, idTag){
console.log(idLocation, idTag); //Console log outputs 1 6, so data is here
return $http({
method: 'GET',
url: $location.protocol() + '://' + $location.host() + '/rest/api/locationtag/locationtag/' + idLocation,
data: {
idTag: idTag
}
}).then(function successCallback(response){
console.log(response);
// response is empty, because data isn't sent to PHP
return response.data;
},function errorCallback(response){
console.log('Error getting slide shows: ' + response.data.message);
});
};
答案 0 :(得分:1)
接收AJAX调用的服务器必须在响应中发送CORS标头,因为它位于不同的端口上。检查一下:http://www.html5rocks.com/en/tutorials/cors/