Just quick examples, so apply validation and authentication and authorization as needed.
public function testc() {
$dogid = Request::input('somevar');
$dog = Dog::find($dogid)->toArray();
return Response::json($dog);
}
And in the success:
success: function (data) {
if (data.error) {
//handle the error
} else {
$('#dogname').val(data.dogname);
$('#comment').val(data.comments);
}
}
public function testg() {
$dogid = Request::input('somevar');
$dog = Dog::select('dogname', 'comments')
->where('dogid', '<', $dogid)
->get()->toArray();
return Response::json($dog);
}
And in success
success: function (data) {
$('#dogname').val(data[0].dogname);
$('#comment').val(data[0].comments);
$('#dogname2').val(data[1].dogname);
$('#comment2').val(data[1].comments);
// just showing two rows
}
for (var i = 0; i < data.length; i++)
{
var item = data[i];
alert(item.dogname + " " + item.comments);
}
// alert just for example
// do what you need to do with the data
Note: Notice the use of
I have never had trouble with a Json response when using that.