Accessing an array outside an ajax call?

Accessing an array outside an ajax call?

all! I have an ajax call grabbing the results of an API. When I try to access that array outside the call, it's blank. Help?

all! I have an ajax call grabbing the results of an API. When I try to access that array outside the call, it's blank. Help?

In the code below, I get the list of properties, then assign the results to the "mlsArray" variable. When I console log it inside main, I get the desired result.

However, if I later call getHomes, the array is empty.

main(auth) {
$.ajax({async: false,
    url: "https://api.simplyrets.com/properties? 
limit=500&lastId=0&status=active&maxprice=" +
    this.maximum + "&type=residential",
    type: 'GET',
    dataType: 'json',
    // authorize with the API credentials
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", "Basic  " + auth);
    },
    success: function(res) {
     this.mlsArray  = Object.assign([], res);
     console.log(this.mlsArray);
    }
  });
}

getHomes() { console.log(this.mlsArray); } }


javascript angular

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Install Angular - Angular Environment Setup Process

Install Angular in easy step by step process. Firstly Install Node.js & npm, then Install Angular CLI, Create workspace and Deploy your App.

Basics of Angular: Part-1

What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular. Angular is a Typesc

How to Build an Angular Application with Angular CLI

How to set up the Angular CLI and generate a Trivial App

The essential JavaScript concepts that you should understand

The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview

Angular Sass: How To Use Sass In Angular 9 Tutorial

Sass in Angular is an extension of CSS that allows you to use things like variables, nested rules, inline imports. Angular supports Sass, CSS, and Less.