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!
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="" src="action. js"></script> <? php $id = $_GET['id']; echo $id; ?>
AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
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.
You need to include all class files again in the tabela_reservas.php
as there is no relation between index.php
and tabela_reservas.php
.
All ajax requests are completely new without any relation to the current(caller) page. Consider those as a new page being called :)
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