0

I have the below:

Notifications.get does exist and work in the long load of code, however at the moment its static, and I want to use ajax, however when I run

Notifications.check(somedate)

I get "undefined" and seemingly no result

Image showing console result

var Notifications = {

    DOM: {
        jQueryContainer: $('#notifications-list'),
        icon: $('#notifications-icon')
    },
    SETTINGS: {
        DEFAULT: {
            sleepTime: 3
        }
    },
    check: function (date) {
        Log.info('Checking for updates');


        $.ajax({
            url: 'api/notifications',
            dataType: 'json',
            type: 'POST',
            data: {
                date: date
            },
            success: function (data) {
                if (data.status == 'PASS') {
                    Log.info('There was updates');
                    // there was an update, update the page
                    Notifications.get();
                }
            }
        });

    },
    init: function () {
        return this;
    }
}.init();

Can anyone tell me what this way of constructing a group of functions is referred to as? (I would say class, but I don't think it is a class?), and if possible it would help to know how to use AJAX inside this. But really if I knew what this way was called I could do my own searches off that :) Thanks!

user1842842
  • 95
  • 1
  • 2
  • 14
  • 2
    The `check` funcntion doesn't return anything, hence the undefined – devqon May 20 '15 at 10:22
  • I don't see a `.get` method there. Where is it? Are you sure that the AJAX request is succeeding? It looks like it's not, so that would explain why `Notifications.get()` is not called. – JLRishe May 20 '15 at 10:26
  • 1
    Possible duplicate: http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call – hindmost May 20 '15 at 10:27
  • I left the get method out as i didnt want to overload the page with code, the get method definitely works – user1842842 May 20 '15 at 10:28
  • My issue was url: 'api/notifications' needed to be url: '/api/notifications' – user1842842 May 20 '15 at 15:21

0 Answers0