logo
down
shadow

redirect in codeigniter using ajax function


redirect in codeigniter using ajax function

By : user2956593
Date : November 22 2020, 10:56 AM
Does that help Send JSON data to ajax as response and handle it according to need.
Contorller:
code :
public function verifyUser()  {

    $userName =  $_POST['email'];
    $userPassword =  $_POST['password'];
    $var=array('email'=>$userName,'password'=>$userPassword);
    $check=$this->mymodel->login_validation($var);


   //$status = array("STATUS"=>"false");
   if(count($check)) {
        $this->output
            ->set_content_type("application/json")
            ->set_output(json_encode(array('status'=>true, 'redirect'=>base_url('main/valid_login') )));
   }
   else {
        $this->output
            ->set_content_type("application/json")
            ->set_output(json_encode(array('status'=>false, 'error'=>'Could't Authorize to the system! Try again with valid credentials.')));
    }   
}
$.ajax({
    type: "post",
    url: "<?php echo site_url('main/verifyUser');?>",
    cache: false,               
    data: $('#userForm').serialize(), 
    dataType: 'json', 
    success:function(response) {
        if( response.status === true )
            document.location.href = response.redirect;
        else 
            $('#show_id').html("<div style='border:1px solid red;font-size: 11px;margin:0 auto !important;'>"+response.error+"</div>");
    }
});


Share : facebook icon twitter icon
CodeIgniter/Ajax - Redirect

CodeIgniter/Ajax - Redirect


By : user2964581
Date : March 29 2020, 07:55 AM
I wish this help you As for the first part of your question:
You can always put data['my_redirect']='site/index' in controller and return that with data['status'], so your site structure wont be 'exposed' for others to view.
How to redirect a page to new window using codeigniter redirect function

How to redirect a page to new window using codeigniter redirect function


By : Premium Expert
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can't use a server-side language (PHP) to control client-side behavior. You can Open a URL in a new tab using JavaScript window.open function.
In codeigniter How to redirect after login using ajax

In codeigniter How to redirect after login using ajax


By : Mitul Methaniya
Date : March 29 2020, 07:55 AM
Hope this helps You need to change few lines of codes in jQuery and Controller function. Here I am attaching updated version of your code. Please refer below:
View (Bootstrap Modal)
code :
<div class="modal-body">
          <form action="<?php echo base_url('Login');?>" method="POST">
             <div class="form-group">
                <input type="text" placeholder="Email or Mobile*" value="" id="loginEmail" name="email" class="form-control input-feild">

             </div>
             <div class="form-group">
                <input type="password" placeholder="Password*" value="" id="loginPassword" name="password" class="form-control input-feild">

             </div>
             <div class="form-group">
                <input type="button" id="l_submit" name="l_submit" value="Login" class="btn btn-primary input-feild">
             </div>
           </form>
           <p id="error-msg"></p>
        </div>
function index() {
    if (!$this->input->is_ajax_request()) {
        echo 'No direct script is allowed';
        die;
    }
    $this->form_validation->set_rules('email', 'Email', 'trim|required');
    $this->form_validation->set_rules('password', 'Password', 'trim|required');

    if ($this->form_validation->run() == false) {
        $result['status'] = 'error';
        $result['message'] = validation_errors();
    }else {
        $email      = $this->input->post("email");
        $password   = $this->input->post("password");
        $user = $this->Perfect_mdl->check_user($email, $password);
        if ($user) {
            $logged_in_data = array();
            foreach ($user as $logged_in_data) {
                $logged_in_data = array(
                    'id' => $user[0]->id,
                    'email' => $user[0]->email
                );
            }
            $this->session->set_userdata($logged_in_data);
            $id = $this->session->userdata('email');
            $data['details'] = $this->Perfect_mdl->get_login_user_detail($id);
            $result['status'] = 'success';
            $result['message'] = 'Yeah! You have successfully logged in.';
$result['redirect_url'] = base_url();
        }else {
            $result['status'] = 'error';
            $result['message'] = 'Whoops! Incorrect Email & Password. Please try again';
        }
    }
    $this->output->set_content_type('application/json');
    $this->output->set_output(json_encode($result));
    $string = $this->output->get_output();
    echo $string;
    exit();
}
<script type="text/javascript">
$("#l_submit").click(function(){

    var email  = $("#loginEmail").val();
    var password   = $("#loginPassword").val();

    $.ajax({
        url : "<?php echo base_url('Login');?>",
        type: 'POST',
        data : {'email':email,'password':password},
        success: function(resp) {

            if (resp.status == "success")
                window.location.href = resp.redirect_url;
            else
                $('#error-msg').html('<div class="alert alert-danger">' + resp.message + '</div>');
        }
    });
    return false;
});
redirect to another page ajax and codeigniter

redirect to another page ajax and codeigniter


By : Icy
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Can anyone help me to give simple solution to redirect page once the user signup form after success. , Add this in your success: function() somewhere:
I want to redirect a controller with AJAX in codeigniter

I want to redirect a controller with AJAX in codeigniter


By : jr7square
Date : March 29 2020, 07:55 AM
it should still fix some issue This may be a silly question.. but why run an ajax call just to reload the page anyways? Would a regular a href not do exactly the same thing but with less hassle? If it were me I would have the function called do something like..
Related Posts Related Posts :
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org