找不到 Angular HTTP 服务 URL 的问题
issue with angular http services url not found
>我正在尝试将数据发布到 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);
});
}
我错过了什么?
您正在尝试传递data
和headers
。jsonp
请求的参数是url
和config
。它不接受data
(与其他类型的请求不同),并且headers
从服务器返回,则无需将它们发送给服务器。我建议您使用 post
请求并返回 json 字符串(那是您使用标头时)。
我建议你阅读这个
除了确保服务器收到您的请求并正确发送响应之外。不确定您尝试将请求发送到何处,但http://myapi.com/registrations.json
不存在。
我必须确保我允许服务器上的跨域。看似交叉多米安测试适用于邮递员,但当您实际尝试时则不然。
相关文章:
- 表单提交问题,如何在我的URL末尾获得ID的值
- 在 UIWebview 中加载带有帖子的 URL 时出现问题
- url的正则表达式有问题
- 有角度的seo友好URL和页面重新加载问题
- 使用jquery从URL中删除查询字符串(处理问题)
- 将 SVG 转换为图像时画布到 URL 功能出现问题
- 替换 URL 字符串中的撇号时出现问题
- 使用 window.open in JavaScript 的 URL 中的“/”问题
- 加载内联 SVG 时填充(url#)出现问题
- 基于 id 访问 url 时存在角度路由问题
- Node JS http-proxy - 创建的 URL 存在问题
- 在 JavaScript 中解码 URL 时遇到问题
- 使用Joomla的jRoute库时POST URL的问题
- 使用 JavaScript 创建干净 URL 的问题
- 从子窗口访问父 URL 时出现问题
- 使用 AngularJS ui-router 深度链接到 URL 的问题
- 匹配 URL 的 JavaScript 问题
- 如何在尝试打印存在警报的URL时解决并发问题
- Ajax调用MVC控制器-URL问题
- Javascript的URL解析问题