weixin_33711647 2013-02-03 01:14 采纳率: 0%
浏览 59

jQuery Ajax强制页面刷新

I have here a form where that accepts user credentials. if the user has invalid user credentials the page will not load however if he or she has valid credentials I want the page to do full page refresh how would I achieve that? I have tried adding.

window.location.href = window.location.href; 

On the response html but it did not work, it seems like jquery is removing the script code?

here's the AJAX for form submission.

$('body').on('submit', '#sign-in', function(e) {
    e.preventDefault();

    var data = $(this).serialize();

    var url = $(this).attr('action');
    $.ajax({
        //this is the php file that processes the data and send mail
        url : url,
        type : "POST",
        data : data,
        //Do not cache the page
        cache : false,
        //success
        success : function(data) {
            alert(data);
            $('#loginModal').html($(data).find('#loginModal').html());
        }
    });
})

if the user has valid credentials the response from the success would be this

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script>
    window.location.href = window.location.href;

</script>
</head>

but the page is not reloading.

  • 写回答

2条回答 默认 最新

  • weixin_33744141 2013-02-03 03:00
    关注

    See if you can use this code in the success function

    On receiving valid response (like 1)

    $(document).attr('location').href='your location'
    
    评论

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)