php - Needle in a haystack jQuery -


basically, i'm producing json array dynamically javascript, i'm doing ajax call returns json data api, want check value inside objects ajax json response see if matches json array, i've tried doing following :

my dynamic json array - json.php

global $wpdb; $ids = array(); $table_name = $wpdb->prefix . "videos"; $idlist = $wpdb->get_results("select `videoid` `$table_name`"); foreach($idlist $id) {      $ids[] = $id->videoid; } echo json_encode(array('idlist' => $ids)); 

my dynamic json output example - json.php

{"idlist":["47","55"]} 

my dynamic json array - javascript

var ids = null; jquery.ajax({     type: "get",     url: pluginurl + "/json.php",     data: "ajaxaction=getids&rand="+math.floor(math.random()*10000),     success: function(data) {         ids = jquery.parsejson(data);     },     error: function() {         alert("error");     } }); 

so that's code that's producing array of id's stored inside database, want use ajax call returns json response api check against these ids, here's code that's returning api response

jquery.ajax({     type: "get",     url: apiurl + "video/" + username,     success: function(data) {         parsed = jquery.parsejson(data);         jquery.each(parsed.user_media, function(i,v){             id = v['id'];             if(jquery.inarray(id,ids['idlist']) !== -1) {                //this isn't working!             }         });     }, }); 

example data output ajax call

{"user_media":[{"id":"2"},{"id":"44"}]} 

as can see i've tried utilise jquery.inarray() no avail, i'm not sure why, may parsing wrong

may ids data not getting set before second ajax call. wrap second ajax call on first ajax call success this:

var ids = null; jquery.ajax({     type: "get",     url: pluginurl + "/json.php",     data: "ajaxaction=getids&rand=" + math.floor(math.random() * 10000),     success: function(data) {         ids = jquery.parsejson(data);          jquery.ajax({             type: "get",             url: apiurl + "video/" + username,             success: function(data) {                 parsed = jquery.parsejson(data);                 jquery.each(parsed.user_media, function(i, v) {                     id = v['id'];                     if (jquery.inarray(id, ids['idlist']) !== -1) {                         //this isn't working!                     }                 });             },         });     },     error: function() {         alert("error");     } }); 

Comments