return without executing the ajax function
function weekData(){
var weekCount={};
$.ajax({
url:"http://localhost:8080/getWeeeks",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
type:"GET",
dataType:"json",
data:{},
success:function(data){
for (var i = 0; i < data.length; i++) {
weekCount[i]=data[i];
}
debugger
return weekCount;
},
});
return weekCount ;
}
var circle = weekData();
3
Answers
You need to adderror
method along with check request on server-side to make sure that your ajax call is working fine.Updated
There are numerous way to get the result from ajax response
async: false
to make ajax response in sync like belowcallback function
Remove the data object from ajax call. There is no need to send any data object when the method type is ‘GET’.
SOLUTION:
Two approaches may work for this:
First use Shorthand Ajax function and store the result into weekCount
Second Option
use
setTimeOut()
function to ensure the request is completed.then callback to store the response in weekCount;