I've been trying to get an ajax function working in Opencart Admin and instead of getting the results from the class method as specified in the ajax url I get either the admin index page or the permission denied page returned. It's as though the class function isn't being called or the token is not being validated correctly.
I've tried including the token in data as well as the url. I've also tried using post and get types.
This is the code that doesn't work but I can't see why
On the client side...
Code: Select all
$.ajax({
type: 'post',
url: 'index.php?route=common/coloradjust/saveChanges?token=<?php echo $token; ?>',
data: format_data,
dataType: 'text',
success: function(text) {
$('#messages').html(text);
}
});
on the server side...
Code: Select all
class ControllerCommonColorAdjust extends Controller {
...
public function saveChanges()
{
echo "This has come back from the function call";
}
}
To get around this for now I've created a hack that works outside the Opencart design and it works..
Client-side (the token is included in the format_data)
Code: Select all
$.ajax({
type: 'post',
url: 'ajax/color_adjust.php',
data: format_data,
dataType: 'text',
success: function(text) {
$('#messages').html(text);
//parent.$('#dialog').remove();
}
});
Code: Select all
<?php
session_start();
// check session token
if ($_REQUEST['token'] != $_SESSION['token'])
{
echo "Invalid Token";
exit;
}
echo "This is the returned results from color_adjust.php<br>";
print_r($_POST);
?>
Any help would be appreciated
thanks.