CodeIgniter Forums
Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] (/showthread.php?tid=75081)



Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] - Nilheim - 12-17-2019

Hello, can someone help? Why do I get a temporary redirect status code when I try to make a get request type in an ajax call?

I'm working in this JS code:

Code:
$('#menu').on('click', 'a', function (event) {
    event.preventDefault();
    if ($(this).attr('href') !== '#') {
        var meta = $("meta[name='database-id']").attr("content");
        var ventana = $('#ventana');
        $.ajax({
            method: 'GET',
            url: $(this).attr('href')
            //data: {'btn': 'na-ver'}
            //dataType: 'json'
        })
        .done(function(data) {
            if (data) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            }
        })
        .fail(function(data) {
            if (data.status === 200) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            } else {
                if (data.responseJSON) {
                    App.respuesta(data.responseJSON);
                } else {
                    App.respuesta(data);
                }
            }
        });
    }
});


The url is well formed, I got this: "http://localhost.scbmk.pro/rol", wich is ok because I have a controller named "rol" and the default method is set to index in app config.

But trying to access to that url via get request doesn't work, it makes a temporary redirect. When accessing via post request the url works perfect, why is this? Do I need to make changes in app conf? remapping route? please heeeeeeeeelp  Cry

I'm working with CI version 4.0.0-rc.3


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request - tgix - 12-18-2019

(12-17-2019, 09:50 PM)Nilheim Wrote: Hello, can someone help? Why do I get a temporary redirect status code when I try to make a get request type in an ajax call?

Have you checked the browser's debugger, specially the network tab? If you are using XHR, you need to make sure to handle the preflight OPTIONS requests correctly, both the routing in CI and the headers.


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request - Nilheim - 12-18-2019

Hello, well... I... don't know how to say this... but... I am truly ashamed...

The problem was a controller filter that I've created myself for redirecting all get requests... Can I say sorry? Blush

I forgot that I created that filter just for testing purposes. Don't know if this post should be closed or eliminated?  Confused


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request - tgix - 12-18-2019

(12-18-2019, 02:16 PM)Nilheim Wrote: Hello, well... I... don't know how to say this... but... I am truly ashamed...

The problem was a controller filter that I've created myself for redirecting all get requests... Can I say sorry? Blush

I forgot that I created that filter just for testing purposes. Don't know if this post should be closed or eliminated?  Confused

Nothing to worry about - happens to all of us sometimes. My solution is to grab another cup of coffee ;-)


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request - InsiteFX - 12-19-2019

You do not need to do anything to this post except edit the forum topic and
add [SOLVED] to the topic title.


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] - kelwein - 12-19-2019

(12-17-2019, 09:50 PM)Nilheim Wrote: Hello, can someone help? Why do I get a temporary redirect status code when I try to make a get request type in an ajax call?

I'm working in this JS code:

Code:
$('#menu').on('click', 'a', function (event) {
    event.preventDefault();
    if ($(this).attr('href') !== '#') {
        var meta = $("meta[name='database-id']").attr("content");
        var ventana = $('#ventana');
        $.ajax({
            method: 'GET',
            url: $(this).attr('href')
            //data: {'btn': 'na-ver'}
            //dataType: 'json'
        })
        .done(function(data) {
            if (data) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            }
        })
        .fail(function(data) {
            if (data.status === 200) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            } else {
                if (data.responseJSON) {
                    App.respuesta(data.responseJSON);
                } else {
                    App.respuesta(data);
                }
            }
        });
    }
});


The url is well formed, I got this: "http://localhost.scbmk.pro/rol", wich is ok because I have a controller named "rol" and the default method is set to index in app config.

But trying to access to that url via get request doesn't work, it makes a temporary redirect. When accessing walmart one via post request the url works perfect, why is this? Do I need to make changes in app conf? remapping route? please heeeeeeeeelp  Cry

I'm working with CI version 4.0.0-rc.3
I have also faced same issue. Did you really find solution??


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] - Nilheim - 12-20-2019

(12-19-2019, 08:13 PM)kelwein Wrote:
(12-17-2019, 09:50 PM)Nilheim Wrote: Hello, can someone help? Why do I get a temporary redirect status code when I try to make a get request type in an ajax call?

I'm working in this JS code:

Code:
$('#menu').on('click', 'a', function (event) {
    event.preventDefault();
    if ($(this).attr('href') !== '#') {
        var meta = $("meta[name='database-id']").attr("content");
        var ventana = $('#ventana');
        $.ajax({
            method: 'GET',
            url: $(this).attr('href')
            //data: {'btn': 'na-ver'}
            //dataType: 'json'
        })
        .done(function(data) {
            if (data) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            }
        })
        .fail(function(data) {
            if (data.status === 200) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            } else {
                if (data.responseJSON) {
                    App.respuesta(data.responseJSON);
                } else {
                    App.respuesta(data);
                }
            }
        });
    }
});


The url is well formed, I got this: "http://localhost.scbmk.pro/rol", wich is ok because I have a controller named "rol" and the default method is set to index in app config.

But trying to access to that url via get request doesn't work, it makes a temporary redirect. When accessing via post request the url works perfect, why is this? Do I need to make changes in app conf? remapping route? please heeeeeeeeelp  Cry

I'm working with CI version 4.0.0-rc.3
I have also faced same issue. Did you really find solution??

Yes, I did. It was a filter controller I created myself for testing purposes about this new feature of CI 4. The filter controller was redirecting to the previous page any http GET request. I disabled it and problem solved.

Some minutes later I started this thread, I remembered about this new feature (filter controllers) and I got in mind that I created some filters for testing... then well I felt like Dodgy ...  Big Grin


RE: Getting Status Code: 307 Temporary Redirect with an ajax get request [SOLVED] - nancychandler340 - 04-21-2022

(12-20-2019, 05:10 PM)Nilheim Wrote:
(12-19-2019, 08:13 PM)kelwein Wrote:
(12-17-2019, 09:50 PM)Nilheim Wrote: Hello, can someone help? Why do I get a temporary redirect status code when I try to make a get request type in an ajax call?

I'm working in this JS code:

Code:
$('#menu').on('click', 'a', function (event) {
    event.preventDefault();
    if ($(this).attr('href') !== '#') {
        var meta = $("meta[name='database-id']").attr("content");
        var ventana = $('#ventana');
        $.ajax({
            method: 'GET',
            url: $(this).attr('href')
            //data: {'btn': 'na-ver'}
            //dataType: 'json'
        })
        .done(function(data) {
            if (data) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            }
        })
        .fail(function(data) {
            if (data.status === 200) {
                ventana.hide();
                ventana.promise().done(function () {
                    ventana.html(data.responseText);
                });
                ventana.fadeIn();
            } else {
                if (data.responseJSON) {
                    App.respuesta(data.responseJSON);
                } else {
                    App.respuesta(data);
                }
            }
        });
    }
});


The url is well formed, I got this: "http://localhost.scbmk.pro/rol", wich is ok because I have a controller named "rol" and the default method is set to index in app config.

But trying to access to that url via get request doesn't work, it makes a temporary redirect. When accessing via post request the url works perfect MyMorri, why is this? Do I need to make changes in app conf? remapping route? please heeeeeeeeelp  Cry

I'm working with CI version 4.0.0-rc.3
I have also faced same issue. Did you really find solution??

Yes, I did. It was a filter controller I created myself for testing purposes about this new feature of CI 4. The filter controller was redirecting to the previous page any http GET request. I disabled it and problem solved.

Some minutes later I started this thread, I remembered about this new feature (filter controllers) and I got in mind that I created some filters for testing... then well I felt like Dodgy ...  Big Grin
Thanks for the update. I will try disabling it and see if it works for me