In controller
List<String> currectTime = userService1.getUserCurrectTime(time,hash);
I need to extract each value from the ajax success responce.
$( ".dropdownlist" ).change(function() {
var time=$('#dropdownlist').val();
var hash=$('#hash').val();
alert(time+hash);
var savedata = {
time:time,
hash:hash
};
$.ajax({
type:'POST',
url:'../test',
data:savedata,
error:function() {
alert("error");
},
success:function(data) {
alert(data);
var obj = JSON.parse(data);
}
});
});
If I alert the response data I see the below
["28-12-2014 01:10:45 NST","30-12-2014 02:40:35 NST","06-11-2014 16:10:45 NST"]
How can I get these values separately.
In controller
List<String> currectTime = userService1.getUserCurrectTime(time,hash);
I need to extract each value from the ajax success responce.
$( ".dropdownlist" ).change(function() {
var time=$('#dropdownlist').val();
var hash=$('#hash').val();
alert(time+hash);
var savedata = {
time:time,
hash:hash
};
$.ajax({
type:'POST',
url:'../test',
data:savedata,
error:function() {
alert("error");
},
success:function(data) {
alert(data);
var obj = JSON.parse(data);
}
});
});
If I alert the response data I see the below
["28-12-2014 01:10:45 NST","30-12-2014 02:40:35 NST","06-11-2014 16:10:45 NST"]
How can I get these values separately.
$.each(obj, function(index, value){console.log(value)})
method would be useful or fixed index like obj[0]
– Girish
Commented
Dec 17, 2014 at 11:18
Simply loop over your object.
var obj = JSON.parse(data);
for (i = 0; i < obj.length; i++) {
console.log(obj[i]);
}
$.each(obj, function(i,data){
alert(data);
});