setDates array format not working

65 Views Asked by At

I want to set dates dynamically on button click. Here is the response what I get from the function:

var result = ['2016-12-05','2016-12-12','2016-12-19','2016-12-26','2016-12-06','2016-12-13','2016-12-20','2016-12-27'
,'2016-12-07','2016-12-14','2016-12-21','2016-12-28','2016-12-01','2016-12-08','2016-12-15','2016-12-22'
,'2016-12-29','2016-12-02','2016-12-09','2016-12-16','2016-12-23','2016-12-30','2016-12-03','2016-12-10'
,'2016-12-17','2016-12-24','2016-12-31','2016-12-04','2016-12-11','2016-12-18','2016-12-25']

If I put above response manually then it works perfectly, but on click of a button it is not working.

If I pass dates from Ajax then it automatically adds " like below:

"'2016-12-05','2016-12-12','2016-12-19','2016-12-26','2016-12-06','2016-12-13','2016-12-20','2016-12-27','2016-12-07','2016-12-14','2016-12-21','2016-12-28','2016-12-01','2016-12-08','2016-12-15','2016-12-22','2016-12-29','2016-12-02','2016-12-09','2016-12-16','2016-12-23','2016-12-30','2016-12-03','2016-12-10','2016-12-17','2016-12-24','2016-12-31','2016-12-04','2016-12-11','2016-12-18','2016-12-25'"

Here is the ajax request:

$.ajax({
    type: "POST",
    data: {month:selected_month},
    url: 'http://test.com/v/get_data',
    success: function(result) {
        var day_of_week = [result];
        $('#spotone').datepicker('setDates', result);
    }
});

Above ajax result is like:

['2016-12-05','2016-12-12','2016-12-19','2016-12-26','2016-12-06','2016-12-13','2016-12-20','2016-12-27','2016-12-07','2016-12-14','2016-12-21','2016-12-28','2016-12-01','2016-12-08','2016-12-15','2016-12-22','2016-12-29','2016-12-02','2016-12-09','2016-12-16','2016-12-23','2016-12-30','2016-12-03','2016-12-10','2016-12-17','2016-12-24','2016-12-31','2016-12-04','2016-12-11','2016-12-18','2016-12-25']
0

There are 0 best solutions below