简体   繁体   中英

JQuery AJAX - How to refresh/reload page using a method GET call

For some reason I can't make this code work, I am trying to reload/refresh the page using GET. All the sample codes that I have found uses POST but I can't go to that because our forms require GET.

This is my code:

        $.ajax({type: "GET", 
            url: "CorrectResults", 
            data: data,
            beforeSend: function() { 
                console.log("Submitting Data");               
            },
            cache: false,
            success: function(html) { 
                  document.location.reload();
                  //location.reload(true);
                  //$("#acceptDiv").html(html);             
           }          
        }); 

It should be a simple way to get this done, why this is so easy with POST and not with GET?

Here we go:

$.ajax({type: "GET", 
            url: "CorrectResults", 
            data: data,
            beforeSend: function() { 
                console.log("Submitting Data");               
            },
            cache: false,
            success: function(html) { 
                  window.location.href= "../yourUrl";          
           }          
        }); 

Hope it helps;)

if you have not any other error in your script( please go to console in your browser press F12), then you can try with location.reload(); in your success method, like that:

$.ajax({type: "GET", 
            url: "CorrectResults", 
            data: data,
            beforeSend: function() { 
                console.log("Submitting Data");               
            },
            cache: false,
            success: function(html) { 
                  location.reload();      
           }          
        }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM