0

I am currently trying to upload some data to my self-written backend using the angularjs $http object. Using this object I have some weird behavior in my coding. When I run my application using the emulator from the Intel XDK IDE I have no problems. When I run the application on my real Smartphone my $http calls make some problems.

I debugged my application and in the network overview my calls return a responsecode 200. Anyways the .error(...) handling is performed and the .success(...) handling is skipped.

My coding looks like this:

 $http({
        method: 'POST',
        url: dbServerPath + "SetStatUser.php",
        data: exporting
    }).success(function (response) {
        console.log(response);

        successSave();

    }).error(function (response, code) {
        console.log(response);
        console.log(code);

        errorSave();
    });

it looks like it returns the error even if the call is not finished.

The problem must be at the frontend. Because I have tested my backend using Postman.

Edit: For further clarification, my backend returns nothing, it just processes the data given with the request payload. Firefox and Google Chrome track the response with the http code 200 but the angularjs object $http tracks it as a 404. So my by backend can not be the trigger for this weird behavior.

nestario
  • 107
  • 1
  • 2
  • 14
  • Use ".then(success, error)" Being success a function for success and error a function for some other response. – yBrodsky Mar 23 '17 at 15:03
  • @yBrodsky Why would using the alternate syntax make a difference? – Casey Mar 23 '17 at 15:06
  • 2
    `success` and `error` are depreciated and are no longer shipped starting from version 1.6. Use `then` instead. I do not know if it addresses this problem or not but you should not use those methods anymore. – Igor Mar 23 '17 at 15:12
  • @Casey because ^ – yBrodsky Mar 23 '17 at 15:13
  • As far as why the 404, use your debugger to see the URL called and the format of the data that is passed in the request body. 404 means the end point was not found, it could be either of the 2 things mentioned above. – Igor Mar 23 '17 at 15:14
  • The request is performed correct, the data is used in the backend correctly, just the returncode ist wrong! With this problem, a reliable error-handling is not possible. – nestario Mar 23 '17 at 15:20
  • Obviously there is a problem with the request OR with your server. The angularjs framework is not wrong otherwise you would definitely not be the first one to experience such a problem. The only way I can see a problem with angularjs is if you 1) using a very old/dated version 2) using an alpha version 3) you manually monkey-patched the framework. – Igor Mar 23 '17 at 15:22
  • @Igor I use angularjs as a part of the Ionic framework, my server can not be the problem as the debugging tool of firefox and google chrome log the request as a 200 – nestario Mar 23 '17 at 15:24
  • To shed more light on your problem I suggest you create an [mcve] and share the back-end code (at least the end point signature and model). – Igor Mar 23 '17 at 15:28

2 Answers2

0

Try to use .then and .catch, might be your successSave() method throwing error and it never caught.

 $http({
            method: 'POST',
            url: dbServerPath + "SetStatUser.php",
            data: exporting
        }).then(function (response) {
            console.log(response);    
            successSave();    
        }, function (error) {
            console.log(error);
            errorSave();
        }).catch(function(err){
           console.log(err);
      });
anoop
  • 3,812
  • 2
  • 16
  • 28
  • 1
    just the same problem, the alternate syntax didn't make any difference – nestario Mar 23 '17 at 15:11
  • please provide more code snippet\some backend code, as I can't see any specific reason for not getting data if you have valid request. that's pretty straight forward – anoop Mar 23 '17 at 15:43
0

I found the solution regarding my problem.

Each request needs a kind of response, even if it just null or {} like in this question: Ajax request returns 200 OK, but an error event is fired instead of success I just added a

echo "null";

to my PHP backend. I hope this will help if someone have the same problem as I had.

Community
  • 1
  • 1
nestario
  • 107
  • 1
  • 2
  • 14