jQuery .html() and .attr() not working after .get() call -


i can't seem jquery change html of div , src of img after receiving data .get ajax call. here code:

function setupuser(method) {     $.get("scripts/loggedin.php", {         method: method     })         .done(function(data) {     $('#loginform').css("display", "none");     $('.account').css("display", "block");     $('#username').html(data.username);     $('#displaypic').attr("src", data.imagepath);     $('.mask').css("visibility", "hidden");     $('.loader').css("visibility", "hidden");     }, "json"); } 

i did console.log() check if data.username , data.imagepath correct , were. when call happens, code executes div , img remain empty. jquery gurus want help?

edit:

fixed! removed "json" end of call , used json.parse(data) instead. fixed code:

function setupuser(method) {     $.get("scripts/loggedin.php", {         method: method     })         .done(function(data) {     var info = json.parse(data);     var imagepath = info.imagepath;     var name = info.username;     console.log(imagepath);     $('#loginform').css("display", "none");     $('.account').css("display", "block");     $('#username').text(name);     $('#displaypic').attr("src", imagepath);     $('.mask').css("visibility", "hidden");     $('.loader').css("visibility", "hidden");     }); } 

it seems "json" converting "data" after text , attr needed set. think.

$('#username').html(data.username); --> try using text()

$('#displaypic').attr('src', data.imagepath); --> imagepath may need formatting relative js file.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -