I cant understand why this happens. I am writing a jquery plugin to fetch records from my database(Mongo) to return back the data. This is how the code looks...
(function() {
var result1;
var image1;
$.fn.showRecs = function() {
var loadData = randomShow();
var result = loadData.complete( function(data) {
$.each(eval(data), function(i,item){
result1 = item.name;
image1 = item.pic1;
if ( image1 == undefined) { image1 = "face_unknown.png"; }
});
});
alert(result1);
this.html("<img src='http://localhost/uploads/" + image1 + "'></img>" + " " + result1);
}
function randomShow() {
return $.ajax({
type: "POST",
url: "http://localhost/action.php",
data: {'showProf' : 1, 'random' : 1 , 'limit2Show' : 1},
datatype : "json",
});
}
}(jQuery) );
Line that shows "this.html" does not show the values unless an alert is prepended before. Why does this happen ? Please let me know to get rid of it.
Also, I am looking to attach a timer to it so that this gets triggered every n seconds, where do i attach it ? Thanks for the help.