简体   繁体   English

Window.location无法正常工作

[英]Window.location doesn't work properly

I want to redirect after my ajax call return succeed. 我想在我的ajax调用返回成功后重定向。 I tried window.location , window.location.href , self.location but page doesn't redirect to target page. 我试过window.locationwindow.location.hrefself.location但是页面没有重定向到目标页面。 Here is my all ajax post codes: 这是我所有的ajax邮政编码:

$(document).on('click', '.btn_Yeni', function (event) {
var date= $("#deSeansTarihi").val();
var _iHastaId= $("#hdnHastaId").val();

date= date.toString().substring(3, 5) + "." + date.toString().substring(0, 2) + "." + date.toString().substring(6, 10);

$.ajax({
    type: "POST",
    url: "KlinikHastalari.aspx/SetNewData",
    data: JSON.stringify({ _dtTarih: date, _id: _iHastaId}),
    dataType: "json",
    async: true,
    contentType: "application/json; charset=utf-8",
    success: function (msg) {
        window.location("http://localhost:59508/trunk/abs.aspx?hid=" + _iHastaId);
    }
});

}); });

SetNewData function returns succeed. SetNewData函数返回成功。 What should I do to redirect target page? 我该怎么做才能重定向目标页面?

window.location works just fine. window.location工作正常。 The problem is you're treating it like a function. 问题是你把它当成一种功能。 It isn't a function, you just assign to it: 它不是一个函数,你只需分配给它:

window.location = "http://localhost:59508/trunk/abs.aspx?hid=" + _iHastaId;

It seems to me like you are using jQuery Mobile in your code. 在我看来,你在代码中使用jQuery Mobile。 Therefore you could also use $.mobile.changePage to redirect to a new page. 因此,您还可以使用$.mobile.changePage重定向到新页面。 Check the reference here: http://api.jquerymobile.com/jQuery.mobile.changePage/ 请查看此处的参考: http//api.jquerymobile.com/jQuery.mobile.changePage/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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