Ajax call successfull but populating data as undefined from web api
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:
Here's what I get when I search by ID:
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
add a comment |
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:
Here's what I get when I search by ID:
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
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 goobjDB.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
add a comment |
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:
Here's what I get when I search by ID:
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
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:
Here's what I get when I search by ID:
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
javascript jquery ajax asp.net-core-webapi asp.net-web-api-routing
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 goobjDB.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
add a comment |
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 goobjDB.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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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);
},
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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);
},
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
add a comment |
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);
},
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
add a comment |
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);
},
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);
},
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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