I am trying to consume a JSON service for client-side data binding.
The service requires a JWT token to be included in a 'Authorization' http header.
I'm assuming i need to implement something on <ClientEvents OnDataBinding="">, but i have little idea where to start.
Any help would be appreciated.
the dataservice is setup as follows
<DataService Location="http://localhost:39338/" DataPath="/list/notifications" EnableCaching="true" ResponseType="JSON" HttpMethod="Get" CountPropertyName="Count" DataPropertyName="Data" />
6 Answers, 1 is accepted
I got it working by doing the following
and then in the markup
it works... not sure if it's best practice though.
Thank you for sharing your solution with the community.
Nevertheless, you should be cautious when using $.ajaxSetup because: "The settings specified here will affect all calls to $.ajax or Ajax-based derivatives such as $.get(). This can cause undesirable behavior since other callers (for example, plugins) may be expecting the normal default settings. For that reason, we strongly recommend against using this API. Instead, set the options explicitly in the call or define a simple plugin to do so."
That is why we recommend configuring the ajax settings per request.
If you need further assistance with the configuration of the request, please share your whole configuration of the ListBox and data source you are using.
Thanks for the response.
Could you possibly point me in the right direction for setting the header for this call only?
This is the full definition of the ListView
and some sample JSON that the service returns
If you need anything else, let me know.
Thank you for the further information.
You can add the beforeSend handler in the AjaxSettings you receive in the OnListViewDataBinding event:
This should add the authentication header similar to Add authentication request headers with ClientDataSource.
just thought I'd put my final solution here.
In the end i decided to use a RadClientDataSource
To add the custom http header, I implemented the OnRequestStart event as follows
Thanks to the assist Peter.
Important to note that the solution provided did work too :)