0

Ive created a backbone.js view that will submit user login details to a codeigniter controller and after verifying it will send a response of boolean value true or false as the authentication status back to ajax.

$data = array(
                'status' => true
            );

            // Send the response back to the client
            print json_encode($data);

When I try to retrieve the response "status" value inside the ondone function of ajax, I get the status value as undefined.

.done(function(data) {
        alert("data: " + data)
        alert("status: " + data.status)
        if (data.status) {
          alert("authenticated")
        } else {
          alert("unauthenticated")
        }
        window.location = '/CW2/ASSWDCW2/cw2app/index.php/Home/';
      });

enter image description here enter image description here

How can I get the status value inside the on done function of ajax?

Kavishka Rajapakshe
  • 537
  • 1
  • 8
  • 23
  • Nothing in the code tells to parse the JSON string. Add the proper http header, and tell jQuery that you're expecting JSON. – Bergi Dec 30 '22 at 06:30

0 Answers0