This is a migrated thread and some comments may be shown as answers.
Pass Date to Amsx Through Datasource
4 Answers 108 Views
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 14 Feb 2012, 04:35 PM
I am working with the datasource control and I am trying to query a webservice and need to pass a start date from a Kendo datepicker.  When it is sent I get an error - Invalid JSON Primitive.  Any help would be appreciated, thanks. Here is my code:
var dataSource = new kendo.data.DataSource({  
 transport: {
  read: {
   url: '/app/handlers/customers.asmx/GetTopAssignedCustomers',
   dataType: "json",
   data: startDate: function(){return kendo.toString(new Date(start.value()), "MM/dd/yyyy");},
   contentType: 'application/json; charset=utf-8',
   type:"POST"     
   }
 },
 schema: {
  data:"d"
 }
});

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Feb 2012, 01:05 PM
Hi William,

You are receiving the error, because the web service expects date/time format in form of "\/Date(x)\/ ", where x is the number of ms elapsed since Jan. 1, 1970. To solve the problem you have to convert JavaScript dates into the required format before sending them to the web server.
So instead of:
function(){return kendo.toString(new Date(start.value()), "MM/dd/yyyy");}
Try using:
function() {
    var converted = '"\\\/Date(' + start.value().getTime() + ')\\\/"';
    return converted;
}

Please let me know if you have any further questions about this problem.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
William
Top achievements
Rank 1
answered on 15 Feb 2012, 02:41 PM
Alexander,

I still get the error.  Here is the text view from Fiddler -

startdate=%22%5C%2FDate(1329282000000)%5C%2F%22&enddate=%22%5C%2FDate(1329282000000)%5C%2F%22&associate=ALL&count=25&storeID=100.

At this point I am assuming the issue is that this data is not being sent correctly as JSON.  Here is my datasource code:

var dataSource = new kendo.data.DataSource({  
    transport: {
        read: {
            url: '/app/handlers/customers.asmx/GetTopAssignedCustomers',
            dataType: "json",
            data:{
                startdate: function(){return ConvertDate(start.value());},
                enddate: function(){return ConvertDate(end.value());},
                associate: function(){return $("#AssociateSelect").val();},
                count: function(){return $("input[name=Count]:checked").val();},
                storeID:"<%=StoreID%>"
                },
            contentType: 'application/json; charset=utf-8',
            type:"POST"                    
            }
    },
    schema: {
        data:"d"
    }
});
0
Alexander Valchev
Telerik team
answered on 16 Feb 2012, 12:18 PM
Hi William,

jQuery does not send the data as JSON by default. Try using JSON.stringify to convert JavaScript data structure into JSON text. You can find more information about that issue here.

Please check the code of that demo, there is an example using stringify method.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
William
Top achievements
Rank 1
answered on 18 Feb 2012, 02:46 AM
Ok, thanks.

Wade
Asked by
William
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
William
Top achievements
Rank 1
Share this question
or