<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2013-06-19 20:29:06Z" class="relativetime">6 years ago</span>.</div>
</div>
</aside>
I'm going nuts with this issue and have no idea what is wrong. What i'm trying to do is a simple AJAX call to get URLs of images and thumbnails for current menu from database. I have a function inside my object literal like this:
infoBlink: function() {
$.ajax({
url: 'ajax.php',
type: 'post',
dataType: 'json',
data: {
'menu_id' : $(".activeMenu").attr('id')
},
error: function(xhr, error){
console.log(xhr);
console.log(error);
},
sucess: function(data){
console.log("success");
console.log(data);
},
});
console.log("menu_id: " + $(".activeMenu").attr('id'));
},
It references a php file with the following code:
require_once('fns/classes/graphics.php');
if(isset($_POST['menu_id']) && !empty($_POST['menu_id'])) {
$menu_id = $_POST['menu_id'];
$gfx = new Graphics();
$result = $gfx->getForId($menu_id);
echo json_encode($result);
}
which then uses a function from Graphics class residing in another file:
public function getForId($menu_id)
{
$query = $this->db->prepare("select * from graphics where menu_id=? ");
$query->bindParam(1, $menu_id);
if ($query->execute()) {
return $query->fetchAll(PDO::FETCH_OBJ);
}
}
Now the thing is, I've tested the ajax.php on it's own and it returns all the needed data from database perfectly, for example:
[{"id":"4","menu_id":"2","name":"logo_v2_vert.jpg","url":"images\/logo_v2_vert.jpg","thumbnail_url":"images\/thumbnails\/logo_v2.jpg"}]
, but when I use AJAX absolutely nothing happens. Neither the error nor the success callback gets executed, just nothing at all. Any help would be much appreciated.
</div>
A quick typo caused all of this. You have success
spelled wrong in your AJAX call. Change:
sucess: function(data){
console.log("success");
console.log(data);
},
To:
success: function(data){
console.log("success");
console.log(data);
},