jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Data Adapter › issue with dataAdapter and ajax call
This topic contains 2 replies, has 2 voices, and was last updated by Peter Stoev 9 years, 11 months ago.
-
Author
-
Hi,
I am unable to fetch data from dataAdapter even though my server side code is returning 2 records (json).
success function is duly called but data.length is 0.
Below is my code, pleas help what the issue is.Thanks,
Keshavan`$(“#addressbutton”).click(function () {
ctype = “hospital”;
recordss = [];
if (ctype != null || ctype != undefined || ctype != ” “) {
$.ajax({
id: ‘CustomerId’,
async: false,
dataType: ‘json’,
url: ‘/Customer/GetCustomers?var=’ + ctype,
type: ‘post’,
data: {},
success: function (data, status, xhr)
{
alert(data.length);
},
error: function (req, status, error)
{
alert(“R: ” + req + ” S: ” + status + ” E: ” + error);
},
complete: function (data) {
recordss[0] = data[0];
}
})
var source = recordss;
var dataAdapterCustomer = new $.jqx.dataAdapter(source,
{
loadComplete: function ()
{
length = dataAdapterCustomer.records.length;
alert(dataAdapterCustomer.records[0]);
},
formatData: function (data){
$.extend(data, {
recordss : data[0]
});
return data;
},
loadError: function (xhr, status, error) {
alert(error);
}
});
})`Hi,
here is formatted code.
$(“#addressbutton”).click(function () { ctype = “hospital”; recordss = []; if (ctype != null || ctype != undefined || ctype != ” “) { $.ajax({ id: ‘CustomerId’, async: false, dataType: ‘json’, url: ‘/Customer/GetCustomers?var=’ + ctype, type: ‘post’, data: {}, success: function (data, status, xhr) { alert(data.length); }, error: function (req, status, error) { alert(“R: ” + req + ” S: ” + status + ” E: ” + error); }, complete: function (data) { recordss[0] = data[0]; } }) var source = recordss; var dataAdapterCustomer = new $.jqx.dataAdapter(source, { loadComplete: function () { length = dataAdapterCustomer.records.length; alert(dataAdapterCustomer.records[0]); }, formatData: function (data){ $.extend(data, { recordss : data[0] }); return data; }, loadError: function (xhr, status, error) { alert(error); } }); })
Hi Keshavan,
I would suggest you to look at the Grid’s data binding demos, or the dataAdapter’s help topic. The dataAdapter in your code is not created correctly.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.