How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

From the jQuery documentation: you specify the asynchronous option to be false to get a synchronous Ajax request. Then your callback can set some data before your mother function proceeds. Here”s what your code would look like if changed as suggested: beforecreate: function (node, targetNode, type, to) { jQuery.ajax({ url: ‘http://example.com/catalog/create/’ + targetNode.id + ‘?name=” … Read more

Asynchronous vs synchronous execution, what is the main difference? [closed]

When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes. That being said, in the context of computers this translates into executing a process or task on another “thread.” A thread is a … Read more

How and when to use ‘async’ and ‘await’

When using async and await the compiler generates a state machine in the background. Here’s an example on which I hope I can explain some of the high-level details that are going on: public async Task MyMethodAsync() { Task<int> longRunningTask = LongRunningOperationAsync(); // independent work which doesn’t need the result of LongRunningOperationAsync can be done … Read more

console.log() async or sync?

console.log is not standardized, so the behavior is rather undefined, and can be changed easily from release to release of the developer tools. Your book is likely to be outdated, as might my answer soon. To our code, it does not make any difference whether console.log is async or not, it does not provide any … Read more

How to return value from an asynchronous callback function? [duplicate]

This is impossible as you cannot return from an asynchronous call inside a synchronous method. In this case you need to pass a callback to foo that will receive the return value function foo(address, fn){ geocoder.geocode( { ‘address’: address}, function(results, status) { fn(results[0].geometry.location); }); } foo(“address”, function(location){ alert(location); // this is where you get the … Read more

Returning data from async call in Swift function

You can pass callback, and call callback inside async call something like: class func getGenres(completionHandler: (genres: NSArray) -> ()) { … let task = session.dataTaskWithURL(url) { data, response, error in … resultsArray = results completionHandler(genres: resultsArray) } … task.resume() } and then call this method: override func viewDidLoad() { Bookshop.getGenres { genres in println(“View Controller: … Read more

How do I return the response from an Observable/http/async call in angular?

Reason: The reason that it’s undefined is that you are making an asynchronous operation. Meaning it’ll take some time to complete the getEventList method (depending mostly on your network speed). So lets look at the http call. this.es.getEventList() After you actually make (“fire”) your http request with subscribe you will be waiting for the response. … Read more

Why is my variable unaltered after I modify it inside of a function? – Asynchronous code reference

One word answer: asynchronicity. Forewords This topic has been iterated at least a couple of thousands of times, here, in Stack Overflow. Hence, first off I’d like to point out some extremely useful resources: @Felix Kling’s answer to “How do I return the response from an asynchronous call?”. See his excellent answer explaining synchronous and … Read more