Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用ajax重定向到索引_Jquery_Html_Ajax - Fatal编程技术网

Jquery 使用ajax重定向到索引

Jquery 使用ajax重定向到索引,jquery,html,ajax,Jquery,Html,Ajax,我开始使用ajax,我想我已经失去了一些。我知道在这个话题上有很多问题,但我还没有找到解决办法 我不明白为什么在提出请求后它没有重定向到索引: 代码如下: var request = jQuery .ajax({ crossDomain: true, url: url_post_end, method: "GET", datatype: "json", beforeSend: function() { $("

我开始使用ajax,我想我已经失去了一些。我知道在这个话题上有很多问题,但我还没有找到解决办法

我不明白为什么在提出请求后它没有重定向到索引:

代码如下:

  var request = jQuery
    .ajax({
      crossDomain: true,
      url: url_post_end,
      method: "GET",
      datatype: "json",
      beforeSend: function() {
        $("#End_btn").prop("disabled", true);
      },
    })
    .done(function(data) {
      window.location = "index.html";
    });
还尝试了:

var request = jQuery.ajax({
    crossDomain: true,
    url: url_post_end,
    method: "GET",
    dataType: "json",
    beforeSend: function() {
      $("#End_btn").prop("disabled", true);
    },
    success: function(data) {
      window.location = "index.html";
    }
  });
它接收的json格式为:{“imgname”:“bla”,“folder”:“/ssa/”}

有人能告诉我为什么页面没有重定向到索引吗

谢谢你的帮助

var请求=jQuery
.阿贾克斯({
跨域:是的,
url:url\u post\u end,
方法:“获取”,
数据类型:“json”,
beforeSend:function(){
$(“End#btn”).prop(“disabled”,true);
},
})
.完成(功能(数据){
window.location.href=“/”;//重定向到主页面
//或
window.location.href=http://www.example.com“;//将带您访问example.com。

});您没有正确重定向<代码>窗口。位置
只是对浏览器当前位置的对象引用。您需要使用
href
来模拟链接单击,或者使用
replace
来模拟HTTP重定向。您还应该捕获错误。如果ajax调用失败,它也将无法重定向,否则您将不知道原因。试试这个:

$.ajax({
url:url\u post\u end,
跨域:是的,
键入:“GET”,
数据类型:“json”,
beforeSend:function(){
$(“End#btn”).prop(“disabled”,true);
},
成功:功能(数据){
window.location.replace=“index.html”;
},
错误:函数(XMLHttpRequest){
log(XMLHttpRequest.responseText);
}
});