I have a problem with Codeigniter and JSON. Here is my coding:
$.post("Admin/Admin/addschool", {test: 'test'}, function(data){
if (data.status == 'ok')
alert(data);
else
alert(data);
}, "json");
... and in my controller:
public function addschool() {
$data = array("status" => "ok", "message"=> "something ");
echo json_encode($data);
exit();
}
But each time my json reply with the HTML of my whole view e.g my response
<!doctype html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://localhost:10090/css/layout.css" />
<title>Administration</title>
<meta name="description" content="">
<meta name="author" content="">
</head>
First, it is good practice not to you used "echo", and you use the 'return'. Try to put down the controller directly to url and see if your return json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With