gpt4 book ai didi

jquery - Ionic 和 Angular JS HTTPS Post 请求

转载 作者:行者123 更新时间:2023-12-01 00:26:44 25 4
gpt4 key购买 nike

我正在尝试通过 Ionic 应用程序中的 post 方法请求 HTTPS 服务器。但每一次,我都失败了。我尝试过2种方法。一种方法是使用 $http,另一种方法是使用 $.ajax。但还是没有找到正确的方法。代码如下。

-使用 $http:

$http({
url: "https://beta.test.com/auth/authenticate/",
method: "POST",
data: {
"userName": "vv9@test.com",
"password": "vv9",
"ipAddress": "2d:5d:3s:1s:3w",
"remeberMe": true
},
headers: {
'Content-Type': 'application/json'
}
}).success(function(res) {
$scope.persons = res; // assign $scope.persons here as promise is resolved here
}).error(function(res) {
$scope.status = res;
});

-使用$.ajax:

$.ajax({
url: "https://beta.test.com/auth/authenticate/",
type: "POST",
data: {
"userName": "vv9@test.com",
"password": "vv9",
"ipAddress": "2d:5d:3s:1s:3w",
"remeberMe": true
},
headers: {
'Content-Type': 'application/json'
}
}).done(function() {
console.log('Stripe loaded');
}).fail(function() {
console.log('Stripe not loaded');
}).always(function() {
console.log('Tried to load Stripe');
});

如何解决这个问题?代码有什么问题?

最佳答案

这里有一些可以帮助您入门的东西,如果您提供一些 plunker 或更多代码,我会更新。

(function() {
'use strict';

angular
.module('example.app', [])
.controller('ExampleController', ExampleController)
.service('exampleServce', exampleServce);

function ExampleController(exampleService) {
var vm = this;

vm.update = function(person, index) {
exampleService.updatePeople(person).then(function(response) {
vm.persons = response;
}, function(reason) {
console.log(reason);
});
};
}


// good practice to use uppercase variable for URL, to denote constant.
//this part should be done in a service

function exampleService($http) {
var URL = 'https://beta.test.com/auth/authenticate/',
data = {
"userName": "vv9@test.com",
"password": "vv9",
"ipAddress": "2d:5d:3s:1s:3w",
"remeberMe": true
},
service = {
updatePeople: updatePeople
};

return service;

function updatePeople(person) {
//person would be update of person.
return $http
.post(URL, data)
.then(function(response) {
return response.data;
}, function(response) {
return response;
});
}
}
})();

关于jquery - Ionic 和 Angular JS HTTPS Post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37059712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com