我正在尝试将数据发布到 api 服务器,但它一直给我 404。我在邮递员中尝试过,它工作正常。由于跨域问题,我正在使用 JSONP 发布数据,这是控制台显示的内容
GET http://myapi.com/registrations.json 404 (Not Found) angular.js:8227
undefined 0 function (name) {
if (!headersObj) headersObj = parseHeaders(headers);
if (name) {
return headersObj[lowercase(name)] || null;
}
return headersObj;
}
Object {method: "JSONP", transformRequest: Array[1], transformResponse: Array[1], url: "http://shipit-integration.herokuapp.com/registrations.json", data: Object…}
data: Object
registration: Object
email: "email@example.com"
password: "pass1234"
__proto__: Object
__proto__: Object
__defineGetter__: function __defineGetter__() { [native code] }
__defineSetter__: function __defineSetter__() { [native code] }
__lookupGetter__: function __lookupGetter__() { [native code] }
__lookupSetter__: function __lookupSetter__() { [native code] }
constructor: function Object() { [native code] }
hasOwnProperty: function hasOwnProperty() { [native code] }
isPrototypeOf: function isPrototypeOf() { [native code] }
propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
toLocaleString: function toLocaleString() { [native code] }
toString: function toString() { [native code] }
valueOf: function valueOf() { [native code] }
get __proto__: function __proto__() { [native code] }
set __proto__: function __proto__() { [native code] }
headers: Object
Accept: "application/json"
Content-Type: "application/json"
__proto__: Object
method: "JSONP"
transformRequest: Array[1]
transformResponse: Array[1]
url: "http://myapi.com/registrations.json"
__proto__: Object
这是我的代码
var data = {
"registration": {
"email": "email@example.com",
"password": "pass1234"
}
};
var headers = {
'Accept': 'application/json',
'Content-Type' : 'application/json'
};
$http({
method: 'JSONP',
url: 'http://myapi.com/registrations.json',
data: data,
headers: headers
}).
success(function (data, status, headers, config) {
console.log(data, status, headers, config);
}).
error(function (data, status, headers, config) {
console.log(data, status, headers, config);
});
}
我错过了什么?