Wednesday, 1 March 2017
jquery - After adding callback function, why is my variable modified inside it unaltered?
Answer
I know it is asynchronicity, but I have followed the steps of adding callback function Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference but I can only access the changes inside the callback function. Here is my code snippet. Please help
function callback(point) {
for (i = 0; i < point.length; i++) {
myDate[i] = point[i].date_time;
myValue[i] = point[i].my_value;
}
for (j = 0; j < myDate.length; j++) {
var temp = new Array(myDate[j], myValue[j]);
mySeries[j] = temp;
}
alert("MYSERIES in scope: " + mySeries); //defined
}
alert("MYSERIES out scope: " + mySeries); // undefined
getAllMessagesforChart(callback);
function getAllMessagesforChart(callback) {
var data = @Html.Raw(JsonConvert.SerializeObject(this.Model))
$.ajax({
url: '/messages/GetMessagesforChat',
data: {
id: data.id,
},
contentType: 'application/html ; charset:utf-8',
type: 'GET',
dataType: 'JSON'
}).success(function (data) {
callback(data);
}).error(function (e) {
alert("error " + e)
})
}
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
How can I detect either numbers or letters in a string? I am aware you use the ASCII codes, but what functions take advantage of the...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
No comments:
Post a Comment