내 AngularJS 앱에서 아래와 같이 HTTP GET 요청을 보내고 있습니다.캐시 된 데이터를 반환하는 AngularJS HTTP GET 요청
MyService.HttpReq("testUrl", "GET", null);
HttpReq
방법은 서비스에 정의하고 다음과 같이 구현됩니다 모든
this.HttpReq = function(URL, method, payload)
{
$http({
url: URL,
method: method,
cache: false,
data: postData,
headers: {
'Content-Type': 'application/json',
}
}).success(function(response)
{
console.log("Success: "+JSON.stringify(response));
}).error(function(data, status)
{
console.error("Error");
});
}
먼저이 AngularJS와의 HTTP 요청을 전송의 올바른 방법인가?
내가 직면하고있는 문제는 때때로 응답으로 캐시 된 데이터를 얻고 HTTP 요청이 서버에 부딪치지 않는다는 것입니다. 무슨 문제가 될 수 있니?
UPDATE
주석과 나는 다음과 같이 내 HTTP 요청 코드를 업데이트 한 대답으로 당,하지만 여전히 같은 문제가 점점.
this.HttpReq = function(URL, method, payload)
{
$http({
url: URL,
method: method,
cache: false,
data: payload,
headers: {
'Content-Type': 'application/json',
'Cache-Control' : 'no-cache'
}
}).
then(
function(response)
{
var data = response.data;
console.log("Success: "+JSON.stringify(data));
},
function(response)
{
var data = response.data || "Request failed";
var status = response.status;
console.error("Error: "+JSON.stringify(data));
}
);
}
HttpReq 메소드에서 어떤 방법을 사용합니까? GET 또는 POST .. 아니면 둘 다? –
GET 및 POST 모두 사용 – User7723337
.success 및 .error는 더 이상 사용되지 않으며 대신 2 개의 콜백 함수를 사용하십시오. – gyc