0

I am new in Famo.us framework. i have small Application in Famo.us framework.

I have following Code:

define(function (require, exports, module) {
    var Surface = require('famous/core/Surface');
    var Modifier = require('famous/core/Modifier');
    var Transform = require('famous/core/Transform');
    var View = require('famous/core/View');
    var HeaderFooterLayout = require('famous/views/HeaderFooterLayout');
    var App = require('./App');


    var apps = [];

    GetContent.prototype = Object.create(View.prototype);
    GetContent.prototype.constructor = GetContent;
    GetContent.DEFAULT_OPTIONS = {};

    function GetContent() {
        View.apply(this, arguments);
        GetData();
    }

    function GetData() {
        $.ajax({
            type: "GET",
            url: "/LocalPlatFormService.svc/GetJobRCompanies",
            contentType: "application/json; charset=utf-8",
            success: ajaxCallSucceed,
            dataType: "json"
        });
    }

    function ajaxCallSucceed(response) {
        var finalStr = '';
        var a = response[0].Success;
        if (a.toString().toLowerCase() == "true") {
            for (var i = 0; i < response.length; i++) {
                var strId = response[i].Id;
                var strSuccess = response[i].Success;
                finalStr += i + '.' + strId + ' , ' + strSuccess + ' ';

                var app1 = new App({});
                app1.AddPages(response[i].ImageLarge, response[i].Description, response.length, i);
                apps.push(app1);
            }
        }
        else {
            alert("No Data Found.");
        }
    }

    module.exports = GetContent;

});

The Ajax call in GetData() is works fine, and it also calls ajaxCallSucceed() on successful Call. but problem is that ajaxCallSucceed() executes after executing all other function, even after executing module.exports = GetContent; in last line.

I want to bind some values in ajaxCallSucceed() based on getting data from database but how to fetch value from ajaxCallSucceed(), as it is executing after all other operation.

Thanks.

ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85

1 Answers1

1

Set ajax async to false. Like this:

$.ajax({
type: "GET",
async: false,
url: "/LocalPlatFormService.svc/GetJobRCompanies",
contentType: "application/json; charset=utf-8",
success: ajaxCallSucceed,
dataType: "json"

});

Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called. If you set async: true then that statement will begin it's execution and the next statement will be called regardless of whether the async statement has completed yet.

Marko Letic
  • 2,460
  • 2
  • 28
  • 34