doudang2817 2014-04-01 16:52
浏览 42
已采纳

处理代码混淆后的Ajax重定向

I have eventually managed to implement an Ajax call in my code but I'm slightly confused how to redirect after the call has been made, an example of my script is seen below, I am developing using CodeIgniter.:

<script type="text/javascript">
  function myFunction() {
    var form_data = $('#form1').serialize();
    $.ajax({
      type: "POST",
      dataType: "text",
      url: "testproject/main/test",
      data: form_data,
      success: function(response){
        window.location("http://www.google.com");
      }
    });
    window.alert("sometext");
  }
</script>

within my test() php function can I have a redirect? if not how can I pass information back to the JS function to redirect? also as a final question how could I use a query such as this to dynamically load html into my page? (the final question is more me being inquisitive/nosey). Many thanks in advance and please exercise patience as I am a complete newbie!

EDIT: my Ajax query executes without an issue however - my code never executes:

success: function(response){
  window.location("http://www.google.com");
}

do I have to return response in php somehow?

  • 写回答

2条回答 默认 最新

  • dounianluo0086 2014-04-01 16:58
    关注

    try this:

    <script type="text/javascript">
        function myFunction()
        {
    
            var form_data = $('#form1').serialize();
    
             $.ajax({
                 type: "POST",
                 dataType: "text",
                 url: "testproject/main/test",
                 data: form_data,
                 success: function(response){
                     window.location.href="http://www.google.com";   
                       // or window.location.assign("http://www.google.com");
                 }
              })
             alert("sometext");
       }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?