This is a migrated thread and some comments may be shown as answers.

Passing custom header information on datasource call

6 Answers 701 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
JD
Top achievements
Rank 1
JD asked on 05 Feb 2013, 09:02 PM
I am trying to set up a call using the datasource control in a html page, based on the following:

http://docs.kendoui.com/api/framework/datasource#transportcreatedata-objectstringfunction

Below is my js function call, and what I am trying to so is pass the customer header called "key" with the value to my restful service, and not sure if I am doing this correctly or not, I am assuming not as I am not seeing this value in my service. So any help you can give on this would be appreciated. Thanks.
function mobileListViewPressToLoadMore() {
       var dataSource = new kendo.data.DataSource({
           pageSize: 20,
           serverPaging: true,
           transport: {
               create: {
                   data: { key: "34083E61DB18E3E88C80DB638C91009A9934757542B538C20E332BBC3F079BE66E79BDC70F06EED8541925D95599E834CF8877D07FAF4645A190BFA3E38A9A3FCB728E043EB8A081B279B81F6F9CED5A"
                   }
               },
               read: {
                   url: "http://services/rest/plan.svc/Patient" // the remove service url
 
 
               },
 
               parameterMap: function (options) {
                   var parameters = {
                       q: "javascript", //additional parameters sent to the remote service
                       rpp: options.pageSize,
                       page: options.page //next page
                   };
 
                   return parameters;
               }
           }, schema: { // describe the result format
               data: "", // the data which the data source will be bound to is in the "results" field
               total: function () { return 0; }
           }
       });
 
       $("#load-more").kendoMobileListView({
           dataSource: dataSource,
           template: $("#load-more-template").text(),
           loadMore: true
       });
 
   }

6 Answers, 1 is accepted

Sort by
0
JD
Top achievements
Rank 1
answered on 05 Feb 2013, 09:14 PM
If you read this post you can see how it is done with jquery ajax call

http://stackoverflow.com/questions/3258645/pass-request-headers-in-a-jquery-ajax-get-call
0
Accepted
Alexander Valchev
Telerik team
answered on 07 Feb 2013, 10:05 PM
Hello JD,

You can use the beforeSend hander with the DataSource's transport too. Please try the following:
dataSource = new kendo.data.DataSource({
    transport: {
        read:  {
            url: "<url>",
            beforeSend: function (xhr) {
                //your code
            },
            dataType: "json"
        }
    }
}

I hope this will help.

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
JD
Top achievements
Rank 1
answered on 08 Feb 2013, 12:51 PM
As they would say in Ireland - Fking A......thanks, that worked like a charm.
0
JD
Top achievements
Rank 1
answered on 08 Feb 2013, 12:52 PM
As they would say in Ireland - Fking A......thanks, that worked like a charm, although I have to ask. Why is that not called out in the documentation on the datasource help?
0
Alexander Valchev
Telerik team
answered on 08 Feb 2013, 04:34 PM
Hello JD,

I am glad to hear that everything works fine now.

The documentation says that "the value of transport.read is passed to jQuery.Ajax". This means that you can use all the jQuery.Ajax settings apart from the success and error event handlers which are wired to the DataSource.

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
JD
Top achievements
Rank 1
answered on 08 Feb 2013, 04:52 PM
Thanks for the explanation, must have missed that while I was looking through this.
Tags
General Discussions
Asked by
JD
Top achievements
Rank 1
Answers by
JD
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or