Reputation: 2790
For my new project, I need to switch pages using AJAX. Because I'm basically a Javascript newbie, I did some research first. Then I tried to code the following:
function loadPage(page) {
$.ajax({
url: "/pages/load.php",
type: "POST",
data: "pagina=" + page,
dataType: "html",
succes: function(loadedPage) {
if (loadedPage != "") {
$("#MainContent").stop(true).animate({
'height' : 0
}, 500).after(loadedPage);
}
else
{
loadPage('404');
}
},
error: function()
{
loadPage('404');
}
});
};
So its pretty basic I guess. This is the PHP code involved with this:
<?php
if (file_exists($_POST['pagina'] . '.tpl'))
{
include($_POST['pagina'] . '.tpl');
}
else
{
include('404.tpl');
}
?>
What I've noticed is that it does nothing. It doesn't show output in the page, neither does it in the console. I've tried different PHP, with the regular ob_get_contents
stuff, but it didn't work either.
I also have confirmed that my edition of jQuery works, that its included before the other JS files, all that kind of stuff.
So how is it that this code doesn't work?
Thanks!
Upvotes: 0
Views: 46
Reputation: 196
It seems that you have a typo in your code.
success: function(loadedPage)
Upvotes: 1