jQuery-Autocomplete
jQuery-Autocomplete copied to clipboard
Why the transformResult does not trigger
Hi,
I want to use transformResult to return the suggestions, but the transformResult does not trigger at all. I check in the Chrome log there is no log printed out, but in the network log I can see there is response from the server and the ajax is called successfully. I don't why, could you help me to figure out?
$('#studentSchoolName').autocomplete({
serviceUrl: '/api/v1/schools/search',
ajaxSettings: {
headers: {
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json'
},
},
method: 'GET',
dataType: 'jsonapi',
transformResult: function(response) {
console.log('------------response Dat', response);
return {
suggestions: responseData.data.map(item => item.attributes.name)
};
},
});
After debugging the code, I found that it is caused by the dataType - jsonapi
DO YOU KNOW HOW MANY DAYS I'VE WASTED FOR THIS!. I was even following the documentation that says to use 'jsonp'. It's 'json' that actually works.