I am trying to get data from MySQL with ajax and here is my code
function Testing()
{
var text;
var langData=[];
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: 'http://localhost/Android/Project/Edu/api/language/read.php',
success:function (data) {
langData = JSON.stringify(data);
for (var i in langData)
{
console.log("row " + i);
for (var j in langData[i])
{
text = text + " " + langData[i][j];
}
}
document.getElementById('LanguageCode').value=text;
},
error: function () {
alert('Failed');
}
});
}
and i got the result as the following
undefined {
" r e c o r d s ": [{
" L a n g u a g e I D ": " 1 ",
" L a n g u a g e N a m e ": " E n g l i s h ",
" L a n g u a g e C o d e ": " E n g ",
" P r i o r i t y ": " 1 ",
" R e g D a t e ": " 2 0 2 0 - 0 7 - 2 9 ",
" S t a t u s ": " A c t i v e "
}, {
" L a n g u a g e I D ": " 2 ",
" L a n g u a g e N a m e ": " C h i n e s e ",
" L a n g u a g e C o d e ": " c n ",
" P r i o r i t y ": " 0 ",
" R e g D a t e ": " 2 0 2 0 - 0 8 - 0 1 ",
" S t a t u s ": " A c t i v e "
}, {
" L a n g u a g e I D ": " 3 ",
" L a n g u a g e N a m e ": " J a p a n e s e ",
" L a n g u a g e C o d e ": " j p ",
" P r i o r i t y ": " 0 ",
" R e g D a t e ": " 2 0 2 0 - 0 8 - 0 1 ",
" S t a t u s ": " A c t i v e "
}]
}
all words / columns name got spacing and i want to create html table using that return data.
how do i Fix it?
text="";before ajaxcall or before 1st for loop.... then you won't receive as undefinedJSON.stringify(data);in your data and your expecteddataTypeasjsoninajaxlangData = JSON.stringify(data);?