I have the following code:
function f(){
var value = "";
var request1 = $.ajax({
url : '/a',
type: "GET"
});
var request2 = $.ajax({
url: '/b',
type: 'GET',
});
$.when(request1, request2).done(function(result1, result2){
//break point #1
//result1 = [Object, "success", Object]
//result2 = [Object, "success", Object]
//do something
})
//break point #2
//request1 = Object {readyState: 1}
//request2 = Object {readyState: 1}
return value
}
When i out the a break point on one place i get that result1 = [Object, "success", Object]
and when i out it on the other place i get that request1 = Object {readyState: 1}
. Please see above.
- What could be the reason for this issue? Is that async issue?
- I want to insert the return value into a parameter. For example:
a = f()
. Is that something i should do with a callback? I've tried to read some articles about it, but haven't managed to implement it, so i would like to get some help. I don't have a lot of experience with JavaScript, so i have some difficult yet to implement such as kind of things.