繁体   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