Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
function myfunction() {
var objTask = {
SenderID: 4, //userid
ScheduleDate: "01 Dec 2016 (Thu)"
}
var pass =[];
$.ajax({
type: "POST",
url: "http://localhost:49534/TaskManagement.svc/TaskList",
data: JSON.stringify(objTask),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status, jqXHR, result) {
for (i = 0; i < data.length; i++) {
pass = [{"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'}];
}
}
});
alert("Loding...");
return pass;
}
JavaScript



What I have tried:

when the above code is i am trying...and the success function retun list of values ....but they return only last list value...how to pass list of values..plz help
Posted
Updated 1-Dec-16 23:37pm

In every iteration your code is setting pass to be an array that contains a single item which is the current item, so each iteration replaces the array before end meaning you end up with only the last one in the loop. Instead in your loop you need to add a single item to the existing array.

pass.push ({"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'});


Above I am using push to add to the array and I am pushing a single item

{ ... }

unlike your original code which was setting an array with a single item

[{ ... }]

(an item is defined by {} and an array by [])
 
Share this answer
 
Comments
venkatesh (chennai) 2-Dec-16 6:00am    
thank you ... i got output
pass[i] = [{"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'}];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900