简体   繁体   English

在Codeigniter中,当未显示在db警报消息中插入数据时,直接重定向

[英]In Codeigniter when insert data in db alert message is not displaying, directly it is redirecting

i am using codigniter .when i am inserting or updating data in mysqldb data is inserting.my form is in popup.then alert is getting but redirecting was not working..issue is redirected is displaying in popup not to page .can you please tell the alternate solution ..i am using ajax update to my form 我正在使用codigniter。当我在mysqldb中插入或更新数据时,正在插入数据。我的表单处于popup.then警报出现但重定向不起作用..issue is redirected在弹出窗口中显示而不是页面。请告诉我替代解决方案..i我正在使用ajax更新到我的表单

This is my code of controller 这是我的控制器代码

    $testid=$this->objTests->updateTest();
    echo "<script> alert('sucessfully updated');</script>"
    redirect(base_url().'tests');

this is my following code of model: 这是我的以下模型代码:

$testData = array('simulationId'  => $this->input-   >post('simulationId'),
                  'testTitle'     => $this->input->post('testTitle'),
                  'description '  => $this->input->post('description')           
            );
    $this->db->where('id',$this->input->post('tid'));
    $this->db->update('tests',$testData);
    return $this->input->post('tid');
$(function(){
  $( "#frmActiontest" ).submit(function( event ) {
     var url = $(this).attr('action');
          $.ajax({
          url: url,
          data: $("#frmActiontest").serialize(),
          type: $(this).attr('method')
        }).done(function(data) {
          //window.location.href="http://neuronguru.com/MedAdmin/tests/";
          window.location.reload();
          /*$('#result').html(data);
          $('#frmActiontest')[0].reset();*/
        });
      event.preventDefault();
  });
  $( ".test" ).on("click",function(event) {
        var url = $(this).data('url');
        var actionUrl = $(this).data('actionurl');
        console.log(actionUrl);
        $("#frmActiontest").attr('action',actionUrl);
        $.ajax({
          url: url,
          type: "GET",
          dataType: 'json'
        }).done(function(data) {
          data=data[0];
          $("#myModalTestLabel").html("Update Test");
          $("#simulationId").val(data.simulationId);
          $("#testTitle").val(data.testTitle);
          $("#description").val(data.description);
          //$("#contents").val(data.contents);
          $("#tid").val(data.id);
          $("#testModal").trigger("click");
          console.log(data);
        });
      event.preventDefault();
  });
  });



  this is my ajax function for the  above question 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM