Display alert message and redirect after click on accept

后端 未结 7 1985
星月不相逢
星月不相逢 2020-12-09 11:23

Well, I have a page with links to reports. Whenever somebody clicks on one report, they can download the excel file. However, sometimes there are no fields to make a report;

相关标签:
7条回答
  • 2020-12-09 11:59

    Combining CodeIgniter and JavaScript:

    //for using the base_url() function
    $this->load->helper('url');
    
    echo "<script type='javascript/text'>";
    echo "alert('There are no fields to generate a report');"
    echo "window.location.href = '" . base_url() . "admin/ahm/panel';"
    echo "</script>";
    

    Note: The redirect() function automatically includes the base_url path that is why it wasn't required there.

    0 讨论(0)
  • 2020-12-09 12:01
    echo "<script>
    alert('There are no fields to generate a report');
    window.location.href='admin/ahm/panel';
    </script>";
    

    and get rid of redirect line below.

    You were mixing up two different worlds.

    0 讨论(0)
  • 2020-12-09 12:04

    use this code to redirect the page

    echo "<script>alert('There are no fields to generate a report');document.location='admin/ahm/panel'</script>";
    
    0 讨论(0)
  • 2020-12-09 12:05

    that worked but try it this way.

    echo "<script>
    alert('There are no fields to generate a report');
    window.location.href='admin/ahm/panel';  
    </script>";
    

    alert on top then location next

    0 讨论(0)
  • 2020-12-09 12:09
    echo "<script>
    window.location.href='admin/ahm/panel';
    alert('There are no fields to generate a report');
    </script>";
    

    Try out this way it works...

    First assign the window with the new page where the alert box must be displayed then show the alert box.

    0 讨论(0)
  • 2020-12-09 12:12

    The redirect function cleans the output buffer and does a header('Location:...'); redirection and exits script execution. The part you are trying to echo will never be outputted.

    You should either notify on the download page or notify on the page you redirect to about the missing data.

    0 讨论(0)
提交回复
热议问题