---
title: "function contents execution not in order"  
description: "function contents execution not in order"  
author: "Anonymous User"  
published: 2013-04-02  
updated: 2013-04-02  
canonical: https://www.mindstick.com/forum/698/function-contents-execution-not-in-order  
category: "javascript"  
tags: ["javascript", "jquery", "mindstick", "free open source", "function contents execution"]  
reading_time: 1 minute  

---

# function contents execution not in order

Hi Expert!\
I have a [javascript function](https://www.mindstick.com/forum/2090/send-data-from-asp-dot-net-code-behind-to-a-javascript-function) as below\
function myfunction() {\
var url = location.href; var ajaxRespose;\
$.ajax({ type:"GET", url: url, cache:false, [dataType](https://www.mindstick.com/forum/160266/explain-the-datatype-data-annotation-and-its-significance-in-data-entry-and-display): "text", [success](https://www.mindstick.com/articles/12957/best-tips-to-make-your-ghostwriting-experience-a-success): function([response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt)) { 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](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) 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](https://www.mindstick.com/interview/34504/difference-between-identity-vs-sequence) of [execution](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net))\
Thanks in advance!

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
Because $.ajax() is asynchronous, the sequence of events happen like this:\
$.ajax(...); // executes AJAX requestconsole.debug("first ajaxResponse:" + ajaxRespose); // undefined\
/* some time later, we receive AJAX response */\
// it executes the success [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) from the original AJAX requestconsole.debug("ajaxRespose ==>:"+ajaxRespose); // [object Object]


---

Original Source: https://www.mindstick.com/forum/698/function-contents-execution-not-in-order

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
