This is the code that works with the img.php file
function loadContato(){
var location = $('.result_File');
var item = "";
$.getJSON("img.php", function(dado){
item += '<p>' + dado[0].username + '</p>';
item += '<img src="avatar/'+dado[0].avatar+'">';
location.html(item);
console.log(item);
});
}
json file information file img_trocar.php
[ { "avatar": "angela.jpg", "username": "angela vazquez", "email_user": "[email protected]" } ]
I'm having trouble with a request from a single line of user information
Here's how the photo shows before sending it to the database okay no problem
function imagemPreview(input) {
var imgpreview = $('#mgpreview');
var iconAVATAR = $('.avatar');
if (input.files && input.files[0]) {
var filerd = new FileReader();
filerd.onload = function (e) {
imgpreview.attr('src', e.target.result);
};
filerd.readAsDataURL(input.files[0]);
}
uploadFoto();
}
The problem is here in this function I'm trying to obiter the user information in JSON format with the $ .getJSON method plus as it's a single line I do not know how to do for () show the information on the page, HELP PLEASE, for security will not be able to show the user data here
function uploadFoto(){
var items = "";
$.getJSON('img_trocar.php', 'GET')
.fail(function(){
$('.result_File').html("ERRO!!");
})
.always(function(data){
for(var i = 0; i < data; i++)
{
items += '<img src="avatar/'+data.avatar+'" alt="avatar">';
items += '<p>'+data[i].username+'</p>';
}
$('.result_File').html(items);
});
}