JQuery AJAX - 如何使用方法 GET 调用刷新/重新加载页面

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

本文关键字:新加载 加载 刷新 AJAX 使用方法 调用 GET JQuery      更新时间:2023-09-26

由于某种原因,我无法使此代码工作,我正在尝试使用GET重新加载/刷新页面。我找到的所有示例代码都使用 POST,但我不能这样做,因为我们的表单需要 GET。

这是我的代码:

        $.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);             
           }          
        }); 

这应该是一种完成此操作的简单方法,为什么使用 POST 而不是 GET 如此简单?

我们来了:

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

希望有帮助;

如果您的脚本中没有任何其他错误(请在浏览器中按 F12 转到控制台),然后你可以试试location.reload();在你的成功方法中,像这样:

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