I am working on a SPA developing in Durandal using Knockout jQuery and Require. My problem is when I make ajax calls to my API I don't actually get my data outside the .then statement(when I substitute my Get method with the line commented out below). However if i work with the current call I cannot use .then it gives me a type undefined error. I have looked at Durandal and they explain about using Q, I have it and referenced in my main. Not sure about the patches mentioned here
var getSearchResult = function (dataHolder,text) {
//return $.getJSON('/Api/Data/GetSearchItem/' + text).done();
jQuery.support.cors = true;
$.ajax({
url: '/Api/Data/GetItem/' + text,
type: 'GET',
dataType: 'json',
success: function (data) {
dataHolder(data);
var check = dataHolder();
return dataHolder();
},
error: function (e) {
}
});
};
I call the method like so:
var search = function (searchText) {
dtx.getSearchResult(searchResult, searchText).then(function () {//(searchResult is an observableArray
searchFlag(true);
var test = searchResult();//i get data here
searchTxt(searchText);
});
var test1 = searchResult();//no data here
};