M
M
MakPET2016-04-16 09:36:31
PHP
MakPET, 2016-04-16 09:36:31

Why does it always return TRUE?

TestApp.controller('MainCtrl', ['$scope','$http', function ($scope,$http) {

  $http.post('test.php')
        .success(function(data){
          console.log(data)
        })
        .error(function(data,status){
          console.log('error');
        })

}])

<?php

echo false;

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Medin K, 2016-04-16
@medin84

I don't know Angular.
But if you expect .error to be executed, the server should return an http error code.
just false is also a value and does not mean that it is an error

I
ILE, 2016-04-16
-Salim @ILE-Salim

Without an error code, the client thinks everything is OK)

V
Vyacheslav Yashnikov, 2016-04-16
@VyacheslavY

TestApp.controller('MainCtrl', ['$scope','$http', function ($scope,$http) {

  $http.post('test.php')
        .success(function(data){
          console.log(data.message)
        })
        .error(function(data,status){
          console.log('error');
        })

}])

<?php 
echo '{"message":false}';
?>

or
TestApp.controller('MainCtrl', ['$scope','$http', function ($scope,$http) {

  $http.post('test.php')
        .success(function(data){
          console.log(data)
        })
        .error(function(data,status){
          console.log('error');
        })

}])

<?php 
echo 'false';
?>

A
Alastor, 2016-04-17
@Alastor

first use echo json_encode(['message' => true]);
secondly, specify the type of content to be transferred in the header;
thirdly, look at the results of the request to begin with

F
f3rm, 2016-04-17
@f3rm

I advise you to study the theory first, at least by the phrase in Google:

implementing restful php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question