Ajax call successfull but populating data as undefined from web api












-1















I cannot figure out why my ajax calls keeps displaying undefined for just this call but in all my other codes it works fine.



Here's what I am getting:



enter image description here



Here's what I get when I search by ID:



enter image description here



here is my code for my ajax:



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;

$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();

$.ajax({
type: "GET",
url: strURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var owner = data;

$("#display").html("<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax));

},
error: function (req, status, error) {
alert("Error: " + req.responseText + " | " + status + " | " + error);
}
}); //end of ajax method
}); // end of btnGetTaxByBL click event


Here is the code for my controller:



[HttpGet("GetByBlockNLot/{block}/{lot}")]
public List<HomeTax> GetByBlockNLot(int block, int lot)
{
List<HomeTax> homeTaxList = new List<HomeTax>();
DBConnect objDB = new DBConnect();
String strSQL = "SELECT * FROM HomeOwnership_T INNER JOIN TaxInfo_T ON HomeOwnership_T.HomeOwnerID=TaxInfo_T.HomeOwnerID WHERE BlockNo =" + block + " AND LotNo =" + lot;
int count = 0;

objDB.GetDataSet(strSQL, out count);

for (int i = 0; i < count; i++)
{
HomeTax objOwner = new HomeTax();
objOwner.HomeOwnerID = (int)objDB.GetField("HomeOwnerID", i);
objOwner.FirstName = (string)objDB.GetField("FirstName", i);
objOwner.LastName = (string)objDB.GetField("LastName", i);
objOwner.Address = (string)objDB.GetField("Address", i);
objOwner.City = (string)objDB.GetField("City", i);
objOwner.State = (string)objDB.GetField("State", i);
objOwner.ZipCode = (string)objDB.GetField("ZipCode", i);
objOwner.TelNo = (string)objDB.GetField("TelNo", i);
objOwner.Email = (string)objDB.GetField("Email", i);
objOwner.BlockNo = (int)objDB.GetField("BlockNo", i);
objOwner.LotNo = (int)objDB.GetField("LotNo", i);
objOwner.SaleDate = (DateTime)objDB.GetField("SaleDate", i);
objOwner.SalePrice = (Decimal)objDB.GetField("SalePrice", i);
objOwner.IsSold = (string)objDB.GetField("IsSold", i);
objOwner.AccessedVal = (Decimal)objDB.GetField("AccessedVal", i);
objOwner.LandVal = (Decimal)objDB.GetField("LandVal", i);
objOwner.AdditionalVal = (Decimal)objDB.GetField("AdditionalVal", i);
objOwner.TaxRate = (Decimal)objDB.GetField("TaxRate", i);
objOwner.TaxPerYear = (Decimal)objDB.GetField("TaxPerYear", i);
objOwner.RealEstateTax = (Decimal)objDB.GetField("RealEstateTax", i);

homeTaxList.Add(objOwner);
}
return homeTaxList;
}









share|improve this question

























  • debugging step 1 - console.log(data) - is it what you expected?

    – Bravo
    Nov 18 '18 at 23:47













  • my array is empty? length of 0

    – pyuntae
    Nov 19 '18 at 0:02











  • well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

    – Bravo
    Nov 19 '18 at 0:14











  • and if the request returns an array, then you're not using it correctly anyway

    – Bravo
    Nov 19 '18 at 0:15











  • Have you looked in your browser console for errors? There should be several

    – Phil
    Nov 19 '18 at 0:57


















-1















I cannot figure out why my ajax calls keeps displaying undefined for just this call but in all my other codes it works fine.



Here's what I am getting:



enter image description here



Here's what I get when I search by ID:



enter image description here



here is my code for my ajax:



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;

$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();

$.ajax({
type: "GET",
url: strURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var owner = data;

$("#display").html("<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax));

},
error: function (req, status, error) {
alert("Error: " + req.responseText + " | " + status + " | " + error);
}
}); //end of ajax method
}); // end of btnGetTaxByBL click event


Here is the code for my controller:



[HttpGet("GetByBlockNLot/{block}/{lot}")]
public List<HomeTax> GetByBlockNLot(int block, int lot)
{
List<HomeTax> homeTaxList = new List<HomeTax>();
DBConnect objDB = new DBConnect();
String strSQL = "SELECT * FROM HomeOwnership_T INNER JOIN TaxInfo_T ON HomeOwnership_T.HomeOwnerID=TaxInfo_T.HomeOwnerID WHERE BlockNo =" + block + " AND LotNo =" + lot;
int count = 0;

objDB.GetDataSet(strSQL, out count);

for (int i = 0; i < count; i++)
{
HomeTax objOwner = new HomeTax();
objOwner.HomeOwnerID = (int)objDB.GetField("HomeOwnerID", i);
objOwner.FirstName = (string)objDB.GetField("FirstName", i);
objOwner.LastName = (string)objDB.GetField("LastName", i);
objOwner.Address = (string)objDB.GetField("Address", i);
objOwner.City = (string)objDB.GetField("City", i);
objOwner.State = (string)objDB.GetField("State", i);
objOwner.ZipCode = (string)objDB.GetField("ZipCode", i);
objOwner.TelNo = (string)objDB.GetField("TelNo", i);
objOwner.Email = (string)objDB.GetField("Email", i);
objOwner.BlockNo = (int)objDB.GetField("BlockNo", i);
objOwner.LotNo = (int)objDB.GetField("LotNo", i);
objOwner.SaleDate = (DateTime)objDB.GetField("SaleDate", i);
objOwner.SalePrice = (Decimal)objDB.GetField("SalePrice", i);
objOwner.IsSold = (string)objDB.GetField("IsSold", i);
objOwner.AccessedVal = (Decimal)objDB.GetField("AccessedVal", i);
objOwner.LandVal = (Decimal)objDB.GetField("LandVal", i);
objOwner.AdditionalVal = (Decimal)objDB.GetField("AdditionalVal", i);
objOwner.TaxRate = (Decimal)objDB.GetField("TaxRate", i);
objOwner.TaxPerYear = (Decimal)objDB.GetField("TaxPerYear", i);
objOwner.RealEstateTax = (Decimal)objDB.GetField("RealEstateTax", i);

homeTaxList.Add(objOwner);
}
return homeTaxList;
}









share|improve this question

























  • debugging step 1 - console.log(data) - is it what you expected?

    – Bravo
    Nov 18 '18 at 23:47













  • my array is empty? length of 0

    – pyuntae
    Nov 19 '18 at 0:02











  • well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

    – Bravo
    Nov 19 '18 at 0:14











  • and if the request returns an array, then you're not using it correctly anyway

    – Bravo
    Nov 19 '18 at 0:15











  • Have you looked in your browser console for errors? There should be several

    – Phil
    Nov 19 '18 at 0:57
















-1












-1








-1








I cannot figure out why my ajax calls keeps displaying undefined for just this call but in all my other codes it works fine.



Here's what I am getting:



enter image description here



Here's what I get when I search by ID:



enter image description here



here is my code for my ajax:



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;

$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();

$.ajax({
type: "GET",
url: strURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var owner = data;

$("#display").html("<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax));

},
error: function (req, status, error) {
alert("Error: " + req.responseText + " | " + status + " | " + error);
}
}); //end of ajax method
}); // end of btnGetTaxByBL click event


Here is the code for my controller:



[HttpGet("GetByBlockNLot/{block}/{lot}")]
public List<HomeTax> GetByBlockNLot(int block, int lot)
{
List<HomeTax> homeTaxList = new List<HomeTax>();
DBConnect objDB = new DBConnect();
String strSQL = "SELECT * FROM HomeOwnership_T INNER JOIN TaxInfo_T ON HomeOwnership_T.HomeOwnerID=TaxInfo_T.HomeOwnerID WHERE BlockNo =" + block + " AND LotNo =" + lot;
int count = 0;

objDB.GetDataSet(strSQL, out count);

for (int i = 0; i < count; i++)
{
HomeTax objOwner = new HomeTax();
objOwner.HomeOwnerID = (int)objDB.GetField("HomeOwnerID", i);
objOwner.FirstName = (string)objDB.GetField("FirstName", i);
objOwner.LastName = (string)objDB.GetField("LastName", i);
objOwner.Address = (string)objDB.GetField("Address", i);
objOwner.City = (string)objDB.GetField("City", i);
objOwner.State = (string)objDB.GetField("State", i);
objOwner.ZipCode = (string)objDB.GetField("ZipCode", i);
objOwner.TelNo = (string)objDB.GetField("TelNo", i);
objOwner.Email = (string)objDB.GetField("Email", i);
objOwner.BlockNo = (int)objDB.GetField("BlockNo", i);
objOwner.LotNo = (int)objDB.GetField("LotNo", i);
objOwner.SaleDate = (DateTime)objDB.GetField("SaleDate", i);
objOwner.SalePrice = (Decimal)objDB.GetField("SalePrice", i);
objOwner.IsSold = (string)objDB.GetField("IsSold", i);
objOwner.AccessedVal = (Decimal)objDB.GetField("AccessedVal", i);
objOwner.LandVal = (Decimal)objDB.GetField("LandVal", i);
objOwner.AdditionalVal = (Decimal)objDB.GetField("AdditionalVal", i);
objOwner.TaxRate = (Decimal)objDB.GetField("TaxRate", i);
objOwner.TaxPerYear = (Decimal)objDB.GetField("TaxPerYear", i);
objOwner.RealEstateTax = (Decimal)objDB.GetField("RealEstateTax", i);

homeTaxList.Add(objOwner);
}
return homeTaxList;
}









share|improve this question
















I cannot figure out why my ajax calls keeps displaying undefined for just this call but in all my other codes it works fine.



Here's what I am getting:



enter image description here



Here's what I get when I search by ID:



enter image description here



here is my code for my ajax:



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;

$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();

$.ajax({
type: "GET",
url: strURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var owner = data;

$("#display").html("<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax));

},
error: function (req, status, error) {
alert("Error: " + req.responseText + " | " + status + " | " + error);
}
}); //end of ajax method
}); // end of btnGetTaxByBL click event


Here is the code for my controller:



[HttpGet("GetByBlockNLot/{block}/{lot}")]
public List<HomeTax> GetByBlockNLot(int block, int lot)
{
List<HomeTax> homeTaxList = new List<HomeTax>();
DBConnect objDB = new DBConnect();
String strSQL = "SELECT * FROM HomeOwnership_T INNER JOIN TaxInfo_T ON HomeOwnership_T.HomeOwnerID=TaxInfo_T.HomeOwnerID WHERE BlockNo =" + block + " AND LotNo =" + lot;
int count = 0;

objDB.GetDataSet(strSQL, out count);

for (int i = 0; i < count; i++)
{
HomeTax objOwner = new HomeTax();
objOwner.HomeOwnerID = (int)objDB.GetField("HomeOwnerID", i);
objOwner.FirstName = (string)objDB.GetField("FirstName", i);
objOwner.LastName = (string)objDB.GetField("LastName", i);
objOwner.Address = (string)objDB.GetField("Address", i);
objOwner.City = (string)objDB.GetField("City", i);
objOwner.State = (string)objDB.GetField("State", i);
objOwner.ZipCode = (string)objDB.GetField("ZipCode", i);
objOwner.TelNo = (string)objDB.GetField("TelNo", i);
objOwner.Email = (string)objDB.GetField("Email", i);
objOwner.BlockNo = (int)objDB.GetField("BlockNo", i);
objOwner.LotNo = (int)objDB.GetField("LotNo", i);
objOwner.SaleDate = (DateTime)objDB.GetField("SaleDate", i);
objOwner.SalePrice = (Decimal)objDB.GetField("SalePrice", i);
objOwner.IsSold = (string)objDB.GetField("IsSold", i);
objOwner.AccessedVal = (Decimal)objDB.GetField("AccessedVal", i);
objOwner.LandVal = (Decimal)objDB.GetField("LandVal", i);
objOwner.AdditionalVal = (Decimal)objDB.GetField("AdditionalVal", i);
objOwner.TaxRate = (Decimal)objDB.GetField("TaxRate", i);
objOwner.TaxPerYear = (Decimal)objDB.GetField("TaxPerYear", i);
objOwner.RealEstateTax = (Decimal)objDB.GetField("RealEstateTax", i);

homeTaxList.Add(objOwner);
}
return homeTaxList;
}






javascript jquery ajax asp.net-core-webapi asp.net-web-api-routing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 0:39









Phil

96.7k11138157




96.7k11138157










asked Nov 18 '18 at 23:40









pyuntaepyuntae

124




124













  • debugging step 1 - console.log(data) - is it what you expected?

    – Bravo
    Nov 18 '18 at 23:47













  • my array is empty? length of 0

    – pyuntae
    Nov 19 '18 at 0:02











  • well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

    – Bravo
    Nov 19 '18 at 0:14











  • and if the request returns an array, then you're not using it correctly anyway

    – Bravo
    Nov 19 '18 at 0:15











  • Have you looked in your browser console for errors? There should be several

    – Phil
    Nov 19 '18 at 0:57





















  • debugging step 1 - console.log(data) - is it what you expected?

    – Bravo
    Nov 18 '18 at 23:47













  • my array is empty? length of 0

    – pyuntae
    Nov 19 '18 at 0:02











  • well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

    – Bravo
    Nov 19 '18 at 0:14











  • and if the request returns an array, then you're not using it correctly anyway

    – Bravo
    Nov 19 '18 at 0:15











  • Have you looked in your browser console for errors? There should be several

    – Phil
    Nov 19 '18 at 0:57



















debugging step 1 - console.log(data) - is it what you expected?

– Bravo
Nov 18 '18 at 23:47







debugging step 1 - console.log(data) - is it what you expected?

– Bravo
Nov 18 '18 at 23:47















my array is empty? length of 0

– pyuntae
Nov 19 '18 at 0:02





my array is empty? length of 0

– pyuntae
Nov 19 '18 at 0:02













well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

– Bravo
Nov 19 '18 at 0:14





well ... there you go objDB.GetDataSet(strSQL, out count); results in no data

– Bravo
Nov 19 '18 at 0:14













and if the request returns an array, then you're not using it correctly anyway

– Bravo
Nov 19 '18 at 0:15





and if the request returns an array, then you're not using it correctly anyway

– Bravo
Nov 19 '18 at 0:15













Have you looked in your browser console for errors? There should be several

– Phil
Nov 19 '18 at 0:57







Have you looked in your browser console for errors? There should be several

– Phil
Nov 19 '18 at 0:57














2 Answers
2






active

oldest

votes


















1














Your API return a list, so you should add a “for” statement to display the list of object, you can’t use the “owner” variable as object because is an Array of objects.






share|improve this answer
























  • I tried this as well but then nothing displays.

    – pyuntae
    Nov 19 '18 at 0:02











  • that's because there is no data - the issue is likely to be on the server side

    – Bravo
    Nov 19 '18 at 0:16











  • there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

    – pyuntae
    Nov 19 '18 at 0:41



















1














Here is your issue



You are using blockNo and lotNo in strURL before they have been assigned a value



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// at this point, blockNo and lotNo are "undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();


simply change the code to get blockNo and lotNo BEFORE using them in strUrl will fix the first issue



$("#btnGetTaxByBL").click(function () {
var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// now you are passing values rather than undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");


The next issue is, that the result is a list (which will, by the looks of it, be sent as an Array) - but you are not using the response as an array



By changing



success: function (data) {
var owner = data;
$("#display").html( ... rest of your code


to



success: function (data) {
var owner = data[0];
$("#display").html( ... rest of your code


i.e. access the FIRST result in the received array, you will now display data as required



If you expect an array, i.e. more than one record, then your code will need to change significantly, because you'll need to iterate through the data and output multiple records



perhaps something like



success: function (data) {
var owner = data;
var html = data.map(function(owner) {
return "<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax);
}).join('');
$("#display").html(html);
},





share|improve this answer


























  • it still gets me undefined but now my console shows the actual data

    – pyuntae
    Nov 19 '18 at 0:31











  • it's an array - let me flesh out the answer

    – Bravo
    Nov 19 '18 at 1:23











  • @Phil - I did so in comments - fleshing out the answer now

    – Bravo
    Nov 19 '18 at 1:23











  • @pyuntae - see updated answer

    – Bravo
    Nov 19 '18 at 1:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366560%2fajax-call-successfull-but-populating-data-as-undefined-from-web-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Your API return a list, so you should add a “for” statement to display the list of object, you can’t use the “owner” variable as object because is an Array of objects.






share|improve this answer
























  • I tried this as well but then nothing displays.

    – pyuntae
    Nov 19 '18 at 0:02











  • that's because there is no data - the issue is likely to be on the server side

    – Bravo
    Nov 19 '18 at 0:16











  • there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

    – pyuntae
    Nov 19 '18 at 0:41
















1














Your API return a list, so you should add a “for” statement to display the list of object, you can’t use the “owner” variable as object because is an Array of objects.






share|improve this answer
























  • I tried this as well but then nothing displays.

    – pyuntae
    Nov 19 '18 at 0:02











  • that's because there is no data - the issue is likely to be on the server side

    – Bravo
    Nov 19 '18 at 0:16











  • there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

    – pyuntae
    Nov 19 '18 at 0:41














1












1








1







Your API return a list, so you should add a “for” statement to display the list of object, you can’t use the “owner” variable as object because is an Array of objects.






share|improve this answer













Your API return a list, so you should add a “for” statement to display the list of object, you can’t use the “owner” variable as object because is an Array of objects.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 '18 at 23:51









Samuel RobertoSamuel Roberto

33817




33817













  • I tried this as well but then nothing displays.

    – pyuntae
    Nov 19 '18 at 0:02











  • that's because there is no data - the issue is likely to be on the server side

    – Bravo
    Nov 19 '18 at 0:16











  • there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

    – pyuntae
    Nov 19 '18 at 0:41



















  • I tried this as well but then nothing displays.

    – pyuntae
    Nov 19 '18 at 0:02











  • that's because there is no data - the issue is likely to be on the server side

    – Bravo
    Nov 19 '18 at 0:16











  • there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

    – pyuntae
    Nov 19 '18 at 0:41

















I tried this as well but then nothing displays.

– pyuntae
Nov 19 '18 at 0:02





I tried this as well but then nothing displays.

– pyuntae
Nov 19 '18 at 0:02













that's because there is no data - the issue is likely to be on the server side

– Bravo
Nov 19 '18 at 0:16





that's because there is no data - the issue is likely to be on the server side

– Bravo
Nov 19 '18 at 0:16













there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

– pyuntae
Nov 19 '18 at 0:41





there is actual data because when i run it thru the url, data displays. so i know it is working. i just don't know why it is not displaying

– pyuntae
Nov 19 '18 at 0:41













1














Here is your issue



You are using blockNo and lotNo in strURL before they have been assigned a value



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// at this point, blockNo and lotNo are "undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();


simply change the code to get blockNo and lotNo BEFORE using them in strUrl will fix the first issue



$("#btnGetTaxByBL").click(function () {
var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// now you are passing values rather than undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");


The next issue is, that the result is a list (which will, by the looks of it, be sent as an Array) - but you are not using the response as an array



By changing



success: function (data) {
var owner = data;
$("#display").html( ... rest of your code


to



success: function (data) {
var owner = data[0];
$("#display").html( ... rest of your code


i.e. access the FIRST result in the received array, you will now display data as required



If you expect an array, i.e. more than one record, then your code will need to change significantly, because you'll need to iterate through the data and output multiple records



perhaps something like



success: function (data) {
var owner = data;
var html = data.map(function(owner) {
return "<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax);
}).join('');
$("#display").html(html);
},





share|improve this answer


























  • it still gets me undefined but now my console shows the actual data

    – pyuntae
    Nov 19 '18 at 0:31











  • it's an array - let me flesh out the answer

    – Bravo
    Nov 19 '18 at 1:23











  • @Phil - I did so in comments - fleshing out the answer now

    – Bravo
    Nov 19 '18 at 1:23











  • @pyuntae - see updated answer

    – Bravo
    Nov 19 '18 at 1:45
















1














Here is your issue



You are using blockNo and lotNo in strURL before they have been assigned a value



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// at this point, blockNo and lotNo are "undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();


simply change the code to get blockNo and lotNo BEFORE using them in strUrl will fix the first issue



$("#btnGetTaxByBL").click(function () {
var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// now you are passing values rather than undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");


The next issue is, that the result is a list (which will, by the looks of it, be sent as an Array) - but you are not using the response as an array



By changing



success: function (data) {
var owner = data;
$("#display").html( ... rest of your code


to



success: function (data) {
var owner = data[0];
$("#display").html( ... rest of your code


i.e. access the FIRST result in the received array, you will now display data as required



If you expect an array, i.e. more than one record, then your code will need to change significantly, because you'll need to iterate through the data and output multiple records



perhaps something like



success: function (data) {
var owner = data;
var html = data.map(function(owner) {
return "<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax);
}).join('');
$("#display").html(html);
},





share|improve this answer


























  • it still gets me undefined but now my console shows the actual data

    – pyuntae
    Nov 19 '18 at 0:31











  • it's an array - let me flesh out the answer

    – Bravo
    Nov 19 '18 at 1:23











  • @Phil - I did so in comments - fleshing out the answer now

    – Bravo
    Nov 19 '18 at 1:23











  • @pyuntae - see updated answer

    – Bravo
    Nov 19 '18 at 1:45














1












1








1







Here is your issue



You are using blockNo and lotNo in strURL before they have been assigned a value



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// at this point, blockNo and lotNo are "undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();


simply change the code to get blockNo and lotNo BEFORE using them in strUrl will fix the first issue



$("#btnGetTaxByBL").click(function () {
var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// now you are passing values rather than undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");


The next issue is, that the result is a list (which will, by the looks of it, be sent as an Array) - but you are not using the response as an array



By changing



success: function (data) {
var owner = data;
$("#display").html( ... rest of your code


to



success: function (data) {
var owner = data[0];
$("#display").html( ... rest of your code


i.e. access the FIRST result in the received array, you will now display data as required



If you expect an array, i.e. more than one record, then your code will need to change significantly, because you'll need to iterate through the data and output multiple records



perhaps something like



success: function (data) {
var owner = data;
var html = data.map(function(owner) {
return "<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax);
}).join('');
$("#display").html(html);
},





share|improve this answer















Here is your issue



You are using blockNo and lotNo in strURL before they have been assigned a value



$("#btnGetTaxByBL").click(function () {
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// at this point, blockNo and lotNo are "undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");

var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();


simply change the code to get blockNo and lotNo BEFORE using them in strUrl will fix the first issue



$("#btnGetTaxByBL").click(function () {
var blockNo = $("#txtBlockNo").val();
var lotNo = $("#txtLotNo").val();
var strURL = "https://localhost:44395/api/ServiceDeed/GetByBlockNLot/" + blockNo + "/" + lotNo;
// now you are passing values rather than undefined
$("#display").html("");
$("#msg").html("");
$("#update").html("");
$("#updateResult").html("");

console.log("btnGetTaxByBL clicked");


The next issue is, that the result is a list (which will, by the looks of it, be sent as an Array) - but you are not using the response as an array



By changing



success: function (data) {
var owner = data;
$("#display").html( ... rest of your code


to



success: function (data) {
var owner = data[0];
$("#display").html( ... rest of your code


i.e. access the FIRST result in the received array, you will now display data as required



If you expect an array, i.e. more than one record, then your code will need to change significantly, because you'll need to iterate through the data and output multiple records



perhaps something like



success: function (data) {
var owner = data;
var html = data.map(function(owner) {
return "<hr><p>".concat("HomeOwnerID: ", owner.HomeOwnerID,
"<br>FirstName: ", owner.FirstName, "<br>LastName: ", owner.LastName,
"<br>Address: ", owner.Address, "<br>City: ", owner.City,
"<br>State: ", owner.State, "<br>ZipCode: ", owner.ZipCode,
"<br>Telephone Number: ", owner.TelNo, "<br>Email: ", owner.Email,
"<br>Block Number: ", owner.BlockNo, "<br>Lot Number: ", owner.LotNo,
"<br>Date of Sale: ", owner.SaleDate, "<br>Sale Price: $", owner.SalePrice,
"<br>Sold Status: ", owner.IsSold, "<br>Accessed Value: ", owner.AccessedVal,
"<br>Land Value: ", owner.LandVal, "<br>Additional Value: ", owner.AdditionalVal,
"<br>Tax Rate: ", owner.TaxRate, "<br>Tax Per Year: ", owner.TaxPerYear,
"<br>Real Estate Tax: ", owner.RealEstateTax);
}).join('');
$("#display").html(html);
},






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 1:44

























answered Nov 19 '18 at 0:20









BravoBravo

41617




41617













  • it still gets me undefined but now my console shows the actual data

    – pyuntae
    Nov 19 '18 at 0:31











  • it's an array - let me flesh out the answer

    – Bravo
    Nov 19 '18 at 1:23











  • @Phil - I did so in comments - fleshing out the answer now

    – Bravo
    Nov 19 '18 at 1:23











  • @pyuntae - see updated answer

    – Bravo
    Nov 19 '18 at 1:45



















  • it still gets me undefined but now my console shows the actual data

    – pyuntae
    Nov 19 '18 at 0:31











  • it's an array - let me flesh out the answer

    – Bravo
    Nov 19 '18 at 1:23











  • @Phil - I did so in comments - fleshing out the answer now

    – Bravo
    Nov 19 '18 at 1:23











  • @pyuntae - see updated answer

    – Bravo
    Nov 19 '18 at 1:45

















it still gets me undefined but now my console shows the actual data

– pyuntae
Nov 19 '18 at 0:31





it still gets me undefined but now my console shows the actual data

– pyuntae
Nov 19 '18 at 0:31













it's an array - let me flesh out the answer

– Bravo
Nov 19 '18 at 1:23





it's an array - let me flesh out the answer

– Bravo
Nov 19 '18 at 1:23













@Phil - I did so in comments - fleshing out the answer now

– Bravo
Nov 19 '18 at 1:23





@Phil - I did so in comments - fleshing out the answer now

– Bravo
Nov 19 '18 at 1:23













@pyuntae - see updated answer

– Bravo
Nov 19 '18 at 1:45





@pyuntae - see updated answer

– Bravo
Nov 19 '18 at 1:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366560%2fajax-call-successfull-but-populating-data-as-undefined-from-web-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?