请求$http.jsonp获取ANgularJS中的值
我试图理解并在一个项目中做一些小的修改。它在请求$http.jsonp获取ANgularJS中的值,angularjs,web-services,jsonp,angular-services,Angularjs,Web Services,Jsonp,Angular Services,我试图理解并在一个项目中做一些小的修改。它在AngularJS jsonp注册表上。以前的注册表有名字,姓氏…就像许多输入一样。但我希望用户输入电子邮件,pw并仅确认密码。然后我已从html文件中删除不需要的输入字段并尝试注册。但我的注册不起作用。如果成功完全响应(注册:1),我的功能应重定向到配置文件页面 Reg.html <form ng-submit="signUp()"> <div class="input-group"> <input id="
AngularJS jsonp
注册表上。以前的注册表有名字,姓氏…就像许多输入一样。但我希望用户输入电子邮件,pw并仅确认密码。然后我已从html文件中删除不需要的输入字段并尝试注册。但我的注册不起作用。如果成功完全响应(注册:1),我的功能应重定向到配置文件页面
Reg.html
<form ng-submit="signUp()">
<div class="input-group">
<input id="email" type="email" ng-model="user.email" required class="form-control" name="email">
</div>
<div class="input-group">
<input type="password" ng-model="user.pwd" required class="form-control" >
</div>
<div class="input-group last-child">
<input type="password" ng-model="user.cpwd" required class="form-control" >
</div>
<button class="btn" type="submit">Sign Up</button>
</form>
Common.js
myApp.factory('Common', function ($http,$window) {
return {
get : function (url, data, callback) {
try {
var req = {};
req.jsonpCallbackParam = 'callback';
req.params = data;
$http.jsonp(window.API_URL + url, req).then(function (response) {
if (response.data) {
callback(response.data, {});
$window.alert("mail "+JSON.stringify(response.data));
} else {
callback({}, "Some Error Occured");
}
});
} catch (err) {
callback({}, err.message);
}
}
});
postman客户端api和common.js警报返回以下响应
Chrome控制台
错误消息
我在您的控制器中没有看到signUp()方法。还有一件事是使用JSONP从服务器获取数据。我认为您应该使用post方法将数据传递到服务器对不起,我编辑了我的post。请使用window.location.href=“您的重定向url”我已经在响应时设置了
警报
。服务返回为空。但是当我尝试使用所有输入字段警报
显示响应时。我已经更新了我的post chrome控制台,显示可能未处理的拒绝:{“数据”:false,“状态”:404,“配置”:
错误
myApp.factory('Common', function ($http,$window) {
return {
get : function (url, data, callback) {
try {
var req = {};
req.jsonpCallbackParam = 'callback';
req.params = data;
$http.jsonp(window.API_URL + url, req).then(function (response) {
if (response.data) {
callback(response.data, {});
$window.alert("mail "+JSON.stringify(response.data));
} else {
callback({}, "Some Error Occured");
}
});
} catch (err) {
callback({}, err.message);
}
}
});