New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove method is hanging pending #193

Closed
devmondo opened this Issue Jul 19, 2013 · 15 comments

Comments

Projects
None yet
9 participants
@devmondo

hi,
when i do for example
listItem.remove();
chrome keeps hanging until i refresh the page

Side note : i have to admit that i have came to see restangular like 3 or 4 times and could not understand the benefit until i played with the code and now i say wow you are genius, i makes life so much easier and code more concise, thanks for this awesome library

@devmondo

This comment has been minimized.

Show comment
Hide comment
@devmondo

devmondo Jul 20, 2013

hi again,
i have made some investigation and using angular's $http works fine, so there must be something wrong here is my code

$scope.remove = function(listItem) {
   //this works                                
  $http({method: 'DELETE', url: '/administration/api/customers/'+listItem.id}).
  success(function(data, status, headers, config) {
      console.log("http delete is ok")
  }).
  error(function(data, status, headers, config) {
      console.log("http delete is not ok")
  });
   //this does not work
    listItem.remove().then(function() {
                     // Updating the list and removing the user after the response is OK.
                    //    $scope.list = _.without($scope.list, listItem);
                    //});
                }

            }

what i have also noticed is that there is difference in the request that is sent, and it maybe causing the problem.

i have also noticed that restangular add this header only to get, while it should be json
Content-Type:application/xml

by the way i am using ASP.NET MVC with IIS 8

the $http method request body :
Accept:application/json, text/plain, /
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ar;q=0.6
Connection:keep-alive
Content-Length:0
Content-Type:application/xml
Host:www.testsite.com
Origin:http://www.testsite.com
Referer:http://www.testsite.com/english/en-us/administration/index
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36

the restangular method request body :

Accept:application/json, text/plain, /
Content-Type:application/xml
Origin:http://www.testsite.com
Referer:http://www.testsite.com/english/en-us/administration/index
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36

hi again,
i have made some investigation and using angular's $http works fine, so there must be something wrong here is my code

$scope.remove = function(listItem) {
   //this works                                
  $http({method: 'DELETE', url: '/administration/api/customers/'+listItem.id}).
  success(function(data, status, headers, config) {
      console.log("http delete is ok")
  }).
  error(function(data, status, headers, config) {
      console.log("http delete is not ok")
  });
   //this does not work
    listItem.remove().then(function() {
                     // Updating the list and removing the user after the response is OK.
                    //    $scope.list = _.without($scope.list, listItem);
                    //});
                }

            }

what i have also noticed is that there is difference in the request that is sent, and it maybe causing the problem.

i have also noticed that restangular add this header only to get, while it should be json
Content-Type:application/xml

by the way i am using ASP.NET MVC with IIS 8

the $http method request body :
Accept:application/json, text/plain, /
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ar;q=0.6
Connection:keep-alive
Content-Length:0
Content-Type:application/xml
Host:www.testsite.com
Origin:http://www.testsite.com
Referer:http://www.testsite.com/english/en-us/administration/index
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36

the restangular method request body :

Accept:application/json, text/plain, /
Content-Type:application/xml
Origin:http://www.testsite.com
Referer:http://www.testsite.com/english/en-us/administration/index
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36

@mgonto

This comment has been minimized.

Show comment
Hide comment
@mgonto

mgonto Jul 20, 2013

Owner

Hey,

remove by default on Restangular sends a request with an empty object.

If you need it to be an empty request, just add a requestInterceptor like:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return undefined;
  } 
  return elem;
});

That's the only difference I see that is important between those 2 requests.

Did you check that the route is the same? Is the route OK?

Bests!

Owner

mgonto commented Jul 20, 2013

Hey,

remove by default on Restangular sends a request with an empty object.

If you need it to be an empty request, just add a requestInterceptor like:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return undefined;
  } 
  return elem;
});

That's the only difference I see that is important between those 2 requests.

Did you check that the route is the same? Is the route OK?

Bests!

@mgonto

This comment has been minimized.

Show comment
Hide comment
@mgonto

mgonto Jul 20, 2013

Owner

I don't remember if it's operation remove or delete but check it out.

Owner

mgonto commented Jul 20, 2013

I don't remember if it's operation remove or delete but check it out.

@devmondo

This comment has been minimized.

Show comment
Hide comment
@devmondo

devmondo Jul 20, 2013

thank you very much for the response, the interceptor worked, why this is causing all the problems ?
before interceptor addition, remove was adding a request load like this but now it is not, so i guess this was the problem, but still i don't know why it would cause a problem, and yes route is the same

{"id":"TestModels/450"}

thank you very much for the response, the interceptor worked, why this is causing all the problems ?
before interceptor addition, remove was adding a request load like this but now it is not, so i guess this was the problem, but still i don't know why it would cause a problem, and yes route is the same

{"id":"TestModels/450"}
@mgonto

This comment has been minimized.

Show comment
Hide comment
@mgonto

mgonto Jul 20, 2013

Owner

The problem was caused because your server doesn't accept payload when doing DELETE.

Owner

mgonto commented Jul 20, 2013

The problem was caused because your server doesn't accept payload when doing DELETE.

@devmondo

This comment has been minimized.

Show comment
Hide comment
@devmondo

devmondo Jul 20, 2013

i have came at this SO thread and if you read darrel comment, he says that HTTP semantics state that Delete with Payload is not semantic

http://stackoverflow.com/a/17427222

i have came at this SO thread and if you read darrel comment, he says that HTTP semantics state that Delete with Payload is not semantic

http://stackoverflow.com/a/17427222

@mgonto

This comment has been minimized.

Show comment
Hide comment
@mgonto

mgonto Jul 20, 2013

Owner

With Restangular you can use whatever you want, that's the idae. If you need no Payload, you can do it, with this configuraiton I sent you above. That's the whole idea of Restangular that you can conigure easily and that it has some safe defaults.

Owner

mgonto commented Jul 20, 2013

With Restangular you can use whatever you want, that's the idae. If you need no Payload, you can do it, with this configuraiton I sent you above. That's the whole idea of Restangular that you can conigure easily and that it has some safe defaults.

@mgonto mgonto closed this Jul 20, 2013

@devmondo

This comment has been minimized.

Show comment
Hide comment
@devmondo

devmondo Jul 21, 2013

very true, thanks again for the support

very true, thanks again for the support

kjlubick added a commit to kjlubick/restangular that referenced this issue Jul 9, 2014

Added empty payload note to remove() docs
Not knowing this particular information caused a coworker and I to spend
4 or 5 hours trying to figure out why Chrome was refusing to make the
remove request.  Long story short, the issue I linked to
(mgonto#193) helped solve the
problem w/o using the $http workaround
@nodesocket

This comment has been minimized.

Show comment
Hide comment
@nodesocket

nodesocket Sep 26, 2014

👍

Just ran across this myself. Using:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return undefined;
  } 
  return elem;
});

Is the solution.

👍

Just ran across this myself. Using:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return undefined;
  } 
  return elem;
});

Is the solution.

@ralbu

This comment has been minimized.

Show comment
Hide comment
@ralbu

ralbu Nov 12, 2014

The above doesn't work for me but this works:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
if (operation === "remove") {
return null;
}
return elem;
});

ralbu commented Nov 12, 2014

The above doesn't work for me but this works:

RestangularProvider.setRequestInterceptor(function(elem, operation) {
if (operation === "remove") {
return null;
}
return elem;
});

@mrova

This comment has been minimized.

Show comment
Hide comment
@mrova

mrova Nov 18, 2014

@ralbu works for me! Thank you!

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return null;
  } 
  return elem;
});

mrova commented Nov 18, 2014

@ralbu works for me! Thank you!

RestangularProvider.setRequestInterceptor(function(elem, operation) {
  if (operation === "remove") {
     return null;
  } 
  return elem;
});
@jasmeetssalech

This comment has been minimized.

Show comment
Hide comment
@jasmeetssalech

jasmeetssalech Feb 25, 2015

How can I pass single parameter say an Integer in customPost and remove?
say a replacement of this:
http://localhost:8080/addClass/'+$scope.classID

Thanks

How can I pass single parameter say an Integer in customPost and remove?
say a replacement of this:
http://localhost:8080/addClass/'+$scope.classID

Thanks

@rhodul

This comment has been minimized.

Show comment
Hide comment
@rhodul

rhodul Sep 1, 2015

It does not work. It still sends {} as payload, and what is worse, it sends Content-Type:text/plain;charset=UTF-8.

rhodul commented Sep 1, 2015

It does not work. It still sends {} as payload, and what is worse, it sends Content-Type:text/plain;charset=UTF-8.

@ezk84

This comment has been minimized.

Show comment
Hide comment
@ezk84

ezk84 Oct 28, 2015

Also run into the Content-Type: text/plain;charset=UTF-8 issue with version 1.5.1 of restangular, this causes problems with my server.

ezk84 commented Oct 28, 2015

Also run into the Content-Type: text/plain;charset=UTF-8 issue with version 1.5.1 of restangular, this causes problems with my server.

@kamleshkrjha

This comment has been minimized.

Show comment
Hide comment
@kamleshkrjha

kamleshkrjha May 4, 2018

setRequestInterceptor is deprecated see here

addRequestInterceptor works.

 RestangularProvider.addRequestInterceptor(function(elem, operation, what, url) {

            if (operation === "remove") {
                return null;
            }

            return elem;

        }); 

setRequestInterceptor is deprecated see here

addRequestInterceptor works.

 RestangularProvider.addRequestInterceptor(function(elem, operation, what, url) {

            if (operation === "remove") {
                return null;
            }

            return elem;

        }); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment