javascript:
$('#menuHome').click(function(ev){ // it's a link
ev.preventDefault();
$.ajax({
type: 'POST',
url: 'combine/ajaxCaller.php',
data: ({fn: 'callHome'}),
dataType: 'json',
success: function(data){
alert(data.header);
},
error: function(){
alert('error');
}
});
});
ajaxCaller.php:
<?php
if(file_exists($file = 'autoLoad.php')){ //don't mind this part
include $file;
}
elseif(file_exists($file = '../autoLoad.php')){
include $file;
}
$functionToCall = $_REQUEST['fn'];
if(function_exists($functionToCall)){
$functionToCall();
}
else{
echo "
{
msg: '$functionToCall () doesn't exist'
}
";
}
function callHome(){
$combine = new homeCombine(); //just somekinda' object
$logic = $combine->_get('homeLogic'); //gets the homeLogic object
echo json_encode(array('header'=>$logic->_get('header'))); // {"header":"Welcome!"}
}
?>
and it's not working
I tried to call it this way and it returns the {"header":"Welcome!"}
<form action="ajaxCaller.php" method="post">
<input name="fn" value="callHome"/>
<input type="submit" value="submit" />
</form>
ohh... I just added
cache: false
and it worked... oh c'mon?
$('#menuHome').click(function(ev){ // it's a link
ev.preventDefault();
$.ajax({
type: 'POST',
url: 'combine/ajaxCaller.php',
data: ({fn: 'callHome'}),
dataType: 'json',
success: function(data){
alert(data.header);
},
error: function(){
alert('error');
}
});
});
ajaxCaller.php:
<?php
if(file_exists($file = 'autoLoad.php')){ //don't mind this part
include $file;
}
elseif(file_exists($file = '../autoLoad.php')){
include $file;
}
$functionToCall = $_REQUEST['fn'];
if(function_exists($functionToCall)){
$functionToCall();
}
else{
echo "
{
msg: '$functionToCall () doesn't exist'
}
";
}
function callHome(){
$combine = new homeCombine(); //just somekinda' object
$logic = $combine->_get('homeLogic'); //gets the homeLogic object
echo json_encode(array('header'=>$logic->_get('header'))); // {"header":"Welcome!"}
}
?>
and it's not working
I tried to call it this way and it returns the {"header":"Welcome!"}
<form action="ajaxCaller.php" method="post">
<input name="fn" value="callHome"/>
<input type="submit" value="submit" />
</form>
ohh... I just added
cache: false
and it worked... oh c'mon?