I have an ajax call to a php page in which I pass an ID using GET.
<script>
$("#oid").change(function(){
var oid = $(this).val();
alert(oid);
$.ajax({
type: "GET",
url: "tabela_reservas.php",
data: "oid="+oid,
success: function(html) {
$("#tabela_reservas").html(html);
}
});
});
</script>
It works, except that PHP gives me an error:
Fatal error: Class ‘Reserva’ not found in C:\xampp\htdocs\kwagenda\tabela_reservas.php on line 20
If I include my class files in the "tabela_reservas.php" it works. But these Class files are already loaded/included in my "index.php" from where I’m calling this ajax page.
My question is: do I need to include my php Class file on "tabela_reservas.php" again or there is another way of doing it?
I ask this because, to me, it doesn’t seem to be a very elegant solution, and it look’s like an overhead, since I’ll be loading twice the same thing on my page.
Is this the right thing to do or there is another way of doing this?
Thanks!
When you make an ajax request to the server, this is a completely new request, just like navigating to another page.
So yes, you need to include everything again.
You should look into autoloading of classes for a more elegant solution to include classes.