forum

Home / DeveloperSection / Forums / function contents execution not in order

function contents execution not in order

Anonymous User155102-Apr-2013
Hi Expert!

I have a javascript function as below

function myfunction() {

    var url = location.href;
    var ajaxRespose;

        $.ajax({
            type:"GET",
            url: url,
            cache:false,
            dataType: "text",
            success: function(response) {
                var data = $.parseJSON(response);
                ajaxRespose = data;
                console.debug("ajaxRespose ==>:"+ajaxRespose);
            }
        });
        console.debug("first ajaxRespose: " +ajaxRespose);
    }
    return false;
}
on my console (firbug) i get :

first ajaxRespose: undefined

ajaxRespose ==>:[object Object]
My question is, why the ajax call execute after the "first" console.debug. PS: i have simplified the function, (function works ok, but problem is in 

sequence of execution)

Thanks in advance!

Updated on 02-Apr-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By