0

I am trying to use put method in http angularJS i am getting an error

Error : XMLHttpRequest cannot load [url]. Response for preflight has invalid HTTP status code 404

My Code is :

var newRentalUrl = serverURL;
var dataObj = JSON.stringify(JSONDATA);

$http.put(newRentalUrl, dataObj, {
  headers: {
    'Content-Type': 'application/json; charset=UTF-8'
  },
}).success(function(responseData) {
  try {
    $ionicLoading.hide();
    console.log(responseData);
    //$state.go('payment');
  } catch (err) {
    console.log(err);
    $ionicLoading.hide();
  }
  $ionicLoading.hide();
}).error(function(data, status, headers, config) {
  $ionicLoading.hide();
  console.log(data);
});

On the server side, the method is received as options

2015-10-21T05:37:02.947517+00:00 heroku[router]: at=info method=OPTIONS path="/v1/home/xx" host=xxxxxx.herokuapp.com request_id=xxxxx-498d-4026-a39a-xxxxxxx fwd="xxx.xxxx.xxx.xxx" dyno=web.1 connect=0ms service=2ms status=404 bytes=481

2
  • have you researched the error to understand what it means? Commented Oct 21, 2015 at 6:24
  • yes I did and this error is that put method is not catch up by the server. Commented Oct 21, 2015 at 9:48

1 Answer 1

1

Change Content-Type to 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'

And if it is a cross-origin resource request you need to add set the CORS header (Access-Control-Allow-Origin ) in your server.

hope it might works.

  var newRentalUrl = serverURL;
        var dataObj = JSON.stringify(JSONDATA);

    $http.put(newRentalUrl, dataObj, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      },
    }).success(function(responseData) {
      try {
        $ionicLoading.hide();
        console.log(responseData);
        //$state.go('payment');
      } catch (err) {
        console.log(err);
        $ionicLoading.hide();
      }

  $ionicLoading.hide();
}).error(function(data, status, headers, config) {
  $ionicLoading.hide();
  console.log(data);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Hello,Thanks for your reply, I had tried the same but not getting result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.