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 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题