Within my project, I have two separate JavaScript files named myJs1.js and myJs2.js. One of the methods in myJs1.js is invoking a method from myJs2.js.
My goal is to retrieve the values r1
and r2
into the results (within myJs1.js).
I attempted to achieve this by declaring the variables r1
and r2
prior to the ajax call, and upon completing the ajax call, I included:
return [r1,r2];
Unfortunately, it returned r1
and r2
as undefined
.
Upon conducting further research, I discovered that adding async: false
might solve the issue, but it comes with various drawbacks (such as browser freezing). Despite attempting this approach, I was still unable to capture the values of r1
and r2.
Note: This is my first time working with AJAX, so please take that into consideration.
UPDATE: In myJs1, there is an ajax call where the method is invoked on success. My intention is to obtain the result to trigger another method within myJs1.
SEE BELOW FOR THE CODE
myJS1:
function method()
{
$.ajax({
type: "GET",
dataType: "json",
url: "http://127.0.0.1:8000/***/***",
success: function(response){
result = methodOfmyJs2(response);
load1(r1); // utilizing r1 from the obtained result
load2(r2); // utilizing r2 from the obtained result
}
})
}
myJs2 :
function methodOfmyJs2(data)
{
$.ajax({
type: "GET",
data: SomeData,
dataType: "json",
url: "http://127.0.0.1:8000/***/***",
success: function(response){
r1 = anotherMethodFromThisJS1(response);
r2 = anotherMethodFromThisJS2(response);
result = [r1, r2]
}
})
}
To proceed, I need to be able to access the values of r1 and r2 for invoking the load1 and load2 methods within myJs1.