Sunday 15 June 2014

javascript - jQuery autocomplete using data pulled from SharePoint list using ajax REST -



javascript - jQuery autocomplete using data pulled from SharePoint list using ajax REST -

i need add together autocomplete input textbox. info needs fetched sharepoint using ajax / rest.

this i've done far:

js

var mydata = []; var requestheaders = { "accept": "application/json;odata=verbose" } $.ajax({ url: "https://my-url/sites/rma-gfplc/_api/web/lists/getbytitle('ad_db')/items? $select=title,regional_x0020_office,commodity,commodity_x0020_year,statelookup/title&$expand=statelookup", type: 'get', datatype: 'json', async: false, headers: requestheaders, success: function (data) { $.each(data.d.results, function (i, result) { mydata.push(result.title); }); mydatasource(mydata); }, error: function ajaxerror(response) { alert(response.status + ' ' + response.statustext); } }); function mydatasource(mydata){ $('#myautocompletesearch').autocomplete({ source: mydata, minlength: 3 }); }

so far code not working, , i'm getting "uncaught typeerror: cannot read property 'label' of null " error in console. i;m wonder doing wrong here? thanks!

this error occurs when source autocomplete function contains element(s) null value.

solution

add status checking if value not null:

$.each(data.d.results, function (i, result) { if(result.title) { mydata.push(result.title); } });

javascript jquery ajax rest sharepoint

No comments:

Post a Comment