Firefox pop up "This web page is being redirected to a new location" on every requestPromise ajax call- is there any way to avoid?

StackOverflow https://stackoverflow.com/questions/20352433

Question

I have a web app with a lot of AJAXing going on. In my original tests this was working fine, but in my testing today, Firefox (on both Mac & IE, on multiple computers), is giving a pop-up message "This web page is being redirected to a new location" for every single PUT & DELETE ajax call, which makes the page a totally unworkable mess. Interestingly, the pop-up does not occur on the GET calls.

The PUT & DELETE are both using an Angular Promise structure, while the GET uses a standard $.http call.

Here's the code of my GET, which does not trigger the pop-up:

 $http({
                method: 'GET',
                url: $scope.faveURL
            }).success(function (data, status, headers, config) {
                if (data === "false") {
                    $scope.faveempty = true;
                    $scope.faveloading = false;
                } else {
                    $scope.favourites = data;
                    $scope.faveloading = false;
                }
            });

And here's the code of my PUT & DELETE, which both do trigger the pop-up:

if (food.favourite === true) {
                requestPromise = $http.put($scope.URL).then(function () {
                    $scope.favourites.push(food);
                    $scope.faveempty = false;
                    food.loading = "none";
                    change = $scope.favouriteChange(food);
                });

            } else if (food.favourite === false) {
                requestPromise =  $http({
                    method: 'DELETE',
                    url: $scope.URL
                }).then(function () {
                    $scope.favourites.splice($scope.favourites.indexOf(food), 1);
                    if ($scope.favourites.length < 1) {
                        $scope.faveempty = true;
                    }
                    food.loading = "none";
                    change = $scope.favouriteChange(food);
                });
            }

Has anyone else experienced this problem while using requestPromise for Ajax calls? Have you found any work-arounds?


UPDATE:

Checking the Network traffic, this is only occurring on AJAX calls which respond with a redirect. This is fine, no pop-up:

[15:09:58.742] GET http://redacted/api/ext/group/35/ [HTTP/1.1 200 OK 381ms]

This causes a pop-up:

[15:03:25.036] PUT http://redacted/api/ext/favorite/713 [HTTP/1.0 301 TYPO3 RealURL redirect 126ms]

So it's a problem with the way the Typo3 services are responding to the PUT & DELETE methods, and Firefox just so happens to have dialog warning for this.

No correct solution

OTHER TIPS

This may not directly help your case, but I was experiencing the same issue and it was due to me having the wrong request type. I am sure it may help others.

Bear in mind I am using jQuery.

Original code:

      $.ajax({
        url: link,
        type: 'json',
        success: function(html) {
          return _this.ajaxLoadIn(html);
        },
        error: function(e) {
          return alert('Sorry, something went wrong, please try again');
        }
      });

Resolved code:

      $.ajax({
        url: link,
        dataType: 'json',
        type: 'get',
        success: function(html) {
          return _this.ajaxLoadIn(html);
        },
        error: function(e) {
          return alert('Sorry, something went wrong, please try again');
        }
      });

As you can see I was setting the wrong "type" parameter. It should have been GET or POST. Hopes this may shed some light.

It is likely your backend doesn't accept URLs without trailing slashes (in case you are using them) and when it meets such a request it tries to redirect you to the right URL (with a trailing slash). This attempt to redirect you to the right URL results in the popup. So make sure you are using URLs with trailing slashes.

Regarding AngularJS RESTful infrustructure, $resource by default removes trailing slashes, but you can turn them on (starting from AngularJS 1.3.0). See more details in the documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top