Error in PUT call angularjs

0

I have a problem with a PUT call in AngularJS.

When making the call to the API at the press of a button, it makes a first request, but then performs a second one, with the same parameters, which generates me in error in the response.

API call

$http.put("http://192.168.20.14:8089/api/v1/ContratoPotencial/?Contratacion_ContratosPotencialesAPIDTO={\"IdEmpresa\": 2,\"IdUsuario\": 1}")
    .then(function successCallback (response) {
      console.log("Insertado! ");
      console.log(response);
    }, function errorCallback(response) {
      console.log("HAY ERROR");
    });

In both cases to enter the success, the problem is that the first call inserts the user and of course, when the second is made, it returns the error that this user already exists.

CONSOLE ERROR

In Chrome console I see the following

As you can see, there is a call where the source is the main.min.js, but the strange thing is that a call comes from an "other" source that I do not launch and it is the one that is spoiling my communication.

    
asked by Diego 08.02.2017 в 12:33
source

1 answer

0

The OPTIONS requests are in no way a failure of AngularJS, on the contrary, they favor the cross-resource communication (APIs).

  

The Cross-Origin Resource Exchange standard works   adding new HTTP headers that allow servers   describe the set of sources that are allowed to read the   information using a web browser. Additionally, for methods of   HTTP request that cause side effects in user data   (in particular, for other HTTP methods than GET, or for   use of POST with some MIME types), the specification suggests   that browsers "verify" the application , requesting methods   supported from the server with an HTTP OPTIONS request method,   and then, with the "approval" of the server, send the true   request with the true HTTP request method. Servers   They can also notify customers when their "credentials"   (including Cookies and HTTP authentication data) must be sent   with requests.

Recommendation allows all entries (CORS) for this type of requests in your web service.

    
answered by 09.02.2017 в 22:50