簡體   English   中英

使用Ajax發布參數時請求中止

[英]Request Aborted on posting params using ajax

通過使用ANCHOR標記,我試圖通過HREF重定向到http://google.com ,但同時我通過AJAX一些參數發布到另一個頁面。重定向工作正常,但是參數發布請求被中止了。
這是我的代碼

<script type="text/javascript">
 $(function(){    
   $('#c').click(function(){           
     $.post("mypage.php?param1=abc1212",function(data){
     });
   });
 return false;  
});
</script>
</head>
<body>
<a id="c" href="http://google.com" class='test'> Click 2 Call</a>

現在頁面完美地移到了google,但是POST請求mypage.php?param1=abc1212被終止了。我不知道為什么嗎?
我可以看到status = aborted在螢火蟲status = aborted
我已經搜索了很多,但是沒有任何線索
請指導我為什么會出現此問題以及如何解決?

<script type="text/javascript">
 $(function(){    
   $('#c').click(function(){           
     $.post("mypage.php?param1=abc1212",function(data){
     });
   });

    window.location.href = "http://google.com";
 return false;  
});
</script>
</head>
<body>
<a id="c" href="#" class='test'> Click 2 Call</a>

您需要的是preventDefault

 $(function(){    
   $('#c').click(function(event){
     event.preventDefault();           
     $.post("mypage.php?param1=abc1212",function(data){
         window.location.href = "http://google.com";
     });
   });
 return false;  
});

preventDefault在單擊時停止錨的重定向,以便您可以執行ajax。 一旦您的ajax完成,然后重定向到谷歌。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM