Skip to content

Instantly share code, notes, and snippets.

@sonnylazuardi
Created July 7, 2015 04:22
Show Gist options
  • Save sonnylazuardi/01927defb32b71eb2b2e to your computer and use it in GitHub Desktop.
Save sonnylazuardi/01927defb32b71eb2b2e to your computer and use it in GitHub Desktop.
CEHA
$(function(){
//$.get( "tes.php", {Loc : "Jakarta", tag: "food"})
//.done(function( data ) {
// var datas = JSON.parse(data);
// handleData(datas);
//alert( "Data Loaded: " + data );
//});
var list = [];
function handleData(data){
var url,temp;
$("#result").html("");
jQuery.each(data,function(){
// console.log(this);
url = 'https://farm'+this.farm+'.staticflickr.com/'+this.server+'/'+this.id+'_'+this.secret+'_m.jpg';
$("#result").html($("#result").html()+"<img title='"+this.title+"' src='"+url+"' class='picture'/>");
});
}
$("#crawl").click(function(){
search();
});
function search2(id){
var deferred = Q.defer();
$.ajax({
url: "tes2.php",
type: "GET",
data: {id:id},
beforeSend: function(){
},
success: function(data,status){
if(status=="success"){
console.log("data");
console.log(data);
console.log("list");
console.log(list);
var x = JSON.parse(data);
var tags = "";
jQuery.each(x.tags.tag,function(){
tags += ","+this.raw;
});
tags = tags.substring(1);
$.each(list, function() {
if(this.id==id){
this["tags"] = tags;
this["owner_location"] = x.owner.location;
}
});
console.log("KELARSSSSS");
deferred.resolve(true);
}
}
});
return deferred.promise;
}
function search(){
var loc = $("#lokasi").val();
var tag = $("#tags").val();
var limit = $("#limit").val();
// console.log(loc+limit+tag);
$.ajax({
url: "tes.php",
type: "GET",
data: {Loc: loc, tag: tag, limit:limit},
beforeSend: function(){
$(".loader").show();
$(".main-content").hide();
},
success: function(data,status){
if(status=="success"){
$(".loader").hide();
$(".main-content").show();
list = JSON.parse(data);
var the_promises = [];
$.each(list, function() {
console.log("REQUESTED");
the_promises.push(search2(this.id));
});
console.log("KELAR");
Q.all(the_promises).then(function(){
console.log("KELAR2");
$('#tab-data').dataTable( {
"data": list,
"columns": [
{ "data": "title" },
{ "data": "picture" },
{ "data": "tags" ,"width":"30px"},
{ "data": "id" },
{ "data": "secret" },
{ "data": "server" },
{ "data": "owner" },
{ "data": "farm" }
],
"columnDefs": [
{ "render": function(data,type,row){
var url = 'https://farm'+row.farm+'.staticflickr.com/'+row.server+'/'+row.id+'_'+row.secret+'_m.jpg';
return "<img title='"+row.title+"' src='"+url+"' class='picture'/>";
},
"targets": 1
},{
"render": function(data,type,row){
return row.tags;
},
"targets": 2
}
],
"bDestroy": true
} );
});
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment