Angularjs $ http post does not work with Chrome browser

I am trying to send an object to a holiday service using angularjs. Unfortunately, it does not work with the Google Chrome browser. Firefox and Internet Explorer work great!

Does anyone have an idea what might be the problem?

Heres my Frontend -call:

    $scope.saveAssignment = function (cap, aId, wId, hId) {

//all the parameters are strings
    var postData = {
        assignmentId: aId,
        status: "CLOSED",
        startDate: new Date(),
        endDate: new Date(),
        captionText: cap,
        workerId: wId,
        segment_Id: hId
    };

    var header ={
        'Content-Type': 'application/json; charset=utf-8'
    };

    $http.post("https://localhost:8443/rest/v1/saveAssignment", postData, header)
        .success(function (data, status, headers, config) {
            console.log("IN SAVE ASSIGNMENTS - SUCCESS");
            console.log(status);
        })
        .error(function (data, status, headers, config) {
            console.log("ERROR!");

//As a response I get data = '' and status = 0
        })
}

I have the same problem if I deploy it (regardless of localhost or not).

On the server side (JPA), I accept the call with:

@Path("saveAssignment")
public class SaveAssignment{
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response saveAss(String assJson) {
    System.out.println("TEST");
......
......
}

But even the print statement "TEST" is not executed ...

UPDATE

This seems to be a CORS problem ... Chrome sends an OPTION request instead of POST ... An idea how to fix this? I have already tried

$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];

but without succes ... :(

UPDATE 2

, . , Chrome (.. )... ( Amazon Mechanical Turk, ). ...: - (

Google Chrome, :

$scope.chrome;

$scope.setIsChrome = function(){
   var chromium = window.chrome;
   var vendorName = window.navigator.vendor;
    if(chromium !== null && vendorName === "Google Inc.") {
      $scope.chrome = true;
    } else {
        $scope.chrome = false;
    }
}

, Opera true "window.chrome", ...

+4
1

angular HTTPS-? localhost:8433 , , Chrome .

URL, https://localhost:8443/, , . .

Update:

iframe, : http://msdn.microsoft.com/en-us/hh563496.aspx

0

Source: https://habr.com/ru/post/1547199/


All Articles