prepareRequest with timeout
HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://include.jaydata.org/datajs-1.1.1beta.min.js"></script>
<script src="http://include.jaydata.org/jaydata.js"></script>
JavaScript
//set up a OData context with dynamic data model
$data.service('https://open.jaystack.net/b8a380cd-b00b-4ce1-8e58-751e615f8dee/1fd8abd2-d697-41ab-9c25-6eee200636d8/api/FlowerDB')
.then(function (contextFactory, contextType) {
//initialize your context instance
var context = contextFactory();
//wait for the context creation
context.onReady(function() {
//customize your request using the prepareRequest hook
context.prepareRequest = function (request) {
//request[0] is the request object
//request[1] is the success callback
//request[2] is the failure callback
request[0].timeoutMS = 5; //datajs time out interval in milliseconds
console.log("timeout: ", request[0].timeoutMS);
};
//query your OData end-point using JayData syntax
context.Flowers
.orderBy('it.Name')
.toArray(function(a){alert("You retrieved " + a.length + " records");}) //display the results in the console
.fail(function() {
alert('fail'); //handle timeout - or any other - errors
});
});
});