I have a similar problem, for 3 days I fight and nothing!
javascript code
var readUrlHome = "/Home/Lergrafico/";
var barChartData;
function getJsonData(idIndicadores, idUgbs) {
$.getJSON(readUrlHome, { IdIndicador: idIndicadores, IdUGB: idUgbs }, function (data) {
barChartData = data;
});
}
var dataFromLoadData;
function loadData(idIndicadores, idUgbs) {
$.getJSON("/Home/LerGrafico/", { data:{ IdIndicador: idIndicadores, IdUGB: idUgbs }, format: "json" }).done(function (data) {
dataFromLoadData = data;
});
}
var dataFromLoadData02;
function LoadData02(idIndicadores, idUgbs) {
var property = this;
this.getingData = function () {
$.getJSON(readUrlHome, { IdIndicador: idIndicadores, IdUGB: idUgbs }, function (data) {
return data;
});
}
}
var dataFromLoadDataAjax;
function LoadDataAjax(idIndicadores, idUgbs) {
var datatoreturn;
$.ajax({
type: 'GET',
dataType: 'json',
url: '/Home/LerGrafico/',
data: { IdIndicador: idIndicadores, IdUGB: idUgbs },
success: function (data, msg) {
dataFromLoadDataAjax = data;
datatoreturn = data;
alert(msg)
}
});
return datatoreturn;
}
this last method displays an alert with successful msg.
the above examples do not work, in all these examples the var declared before the method continues Undefined, one of these methods ai, whatever it worked, is called inside another function executed when I choose an item in a drop down list.
Any idea what I can do?
Editing:
I managed to make it work, instead of the get json returning the result by storing in a variable I put the javascript method that would make use of the requested data, I had tried before but had given an error in a value among the returned data, when I stopped to check I realized it was a mistake to carry this wrong value in the chartjs. I thought the call was not working but the error was in the assembly of the chartjs, after realizing that I changed that value and it worked.
can’t reproduce your error here dude. I tried to access this URL directly in the browser and it worked. I tried to create a . html and run it, it worked. :/
– tayllan
But it prints the json values on the page ? Here it doesn’t print the value and when I open the console in Firefox it has this error.
– Carlos
No longer giving this error. I think I was wrong. But it still doesn’t work. As I said, it is returning Undefined.
– Carlos