I have two js files i.e. myJs1.js and myJs2.js . From myJs1.js a method of myJs2.js is called.
I want to return r1
and r2
into results(in myJs1.js)
I have tried this:
I declared r1
and r2
variables before the ajax call and
after the ajax call I added:
return [r1,r2];
But it return r1
and r2
as undefined
.
When I researched the issue I came across that adding async: false
could work but it has so many issues (like browser freezing). Even so I tried it and still was not able to get the values of r1
and r2.
Note: I am uing AJAX for the first time so bear that in mind.
EDIT: There is an ajax call in Js1 in which on success event the method is called. I want to access the result to call another method in the js1
EDIT:LOOK HERE 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); //r1 from result
load2(r2); //r2 from 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]
}
})
}
I need to access the value of r1 and r2 to call load1 and load2 method of myJs1.