Help! i am learning php through online tutorial and the best way to learn is to do something, i actually did in the procedural way and it works, now i'm doing the same thing in OOP and MVC(my own implementation of mvc just for learning), it's also going well until i have to use jquery/ajax... Now my problem is the response received in JSON.
Here is the screenshot of the same Ajax call response in procedural which works:
Here is the screenshot of the same Ajax call response in OOP/MVC which doesn't work:
Code of page containing the jQuery:
$("#full-input").on('change', function() {
var customer = $("#full-input").val();
$.ajax({
url: 'getSingle',
data: {id: customer},
type: 'post',
success: function (result) {
alert(result);//for debuging
}
});
});
Controller to handle the request:
class CustomerController extends Controller{
public function index(){
$customer = new CustomerModel();
$data = $customer->index();
$this->setData($data);
$this->setTitle('Customer List');
$this->setView(VIEW_PATH.'customer/all_cust.php');
}
public function getSingle(){
$sintgle = new CustomerModel();
if(isset($_POST['id'])){
$result = $sintgle->singleCust($_POST['id']);
echo json_encode($result);
$this->setTitle('Single Customer');
}else{
$data = $sintgle->index();//gets all customers to populate drop-down select
$this->setData($data);
$this->setTitle('Select Customer');
$this->setView(VIEW_PATH.'customer/single_cust.php');
}
}
}
What am i not doing right here?