HTTP API Method to get data performing Server-Side Code
HTTP API Method to get data performing Server-Side Code
nayansufism
Posts: 4Questions: 1Answers: 0
I am using Below code to fetch data from API HTTP Method. I didn't find any link or solution which get data from HTTP method without any ajax or PHP code. As i am using Angularjs.
I also get warning that invalid JSON. But My json response is valid.
Please suggest some solution.
var table = $('#dataTable').DataTable({
"processing": true,
"serverSide": true,
"ajax":{
"contentType": "json",
"data": function(d){
$http.get("http://abcd.com/v0/events/search?noOfResultsPerPage=1")
.success(function (response) {
$("#loading-animation").hide();
response.splice(0,1);
console.log(JSON.stringify(response));
//d.extra_search = response;
d =response;
return d;
})
.error(function (response) {
$scope.data12 = {};
//d.extra_search = data12;
return data12;
})
}
},
"columns": [
{'data': 'eventId'},
{'data': 'name'},
{'data': 'location'},
{'data': 'venue'},
{'data': 'company'},
{'data': 'description'}
]
});
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Replies
Do you want to provide your own Ajax call to get the data? If so use
ajax
as a function - notajax.data
. The latter defines the data that is sent to the server when DataTables makes its own Ajax requests.Allan
Hi Allan,
Thanks for the reply!
Basically, I have to fetch data from server side in Datatables. It will include search and other operations dynamically from server at runtime. I tried that with above code snippet and I am not able to figure out.
In general, I am running into "Invalid JSON" issue. Can you please give me some links or relevant pointers which can help me in communicating to server and populating datatables dynamically? Data will be fetched using REST API.
Thanks a lot!
The tech note that the error you mention links to is the best starting point. It will let you see what is being returned since it isn't valid JSON.
How to create valid JSON is something that you would need to research for whatever programming language you are using and is outside the scope of this forum.
Allan