javascript - Populate table with variable created from ajax response -
i have table populated data need use run second query. using jquery datatables , functions see allow me grab content table. example grabbing integer out of fourth column , using number run query json response :
var cells = []; var rows = otable.fngetnodes(); for( var i=0;i<rows.length;i++) { var grabsku = $j(rows[i]).find('td:eq(3)').text(); grabsku = grabsku.substring(0, 6) + "-0" + grabsku.substring(7, grabsku.length - 4); s7url = 'http://jsonquery.com/' + grabsku + '?req=exists,json'; $j.ajax({ url: s7url, datatype: 'jsonp' }); }
then ajax request json returns either 1 or 0 can form correct info depending on returned.
function s7jsonresponse(response) { var s7img = sku; s7img = '<img src="http://imageserver.com/is/image/' + s7img.substring(0, 6) + "-0" + s7img.substring(7, s7img.length - 4) + '">'; x = response["catalogrecord.exists"]; z = x == "0" ? "no img" : s7img; console.log(z); }
console shows me want z variable, either image path or no img. problem getting out of console , table. want happen each response comes in replace td in table z variable. tried put in jsonresponse did not work correctly. how iterate through table, in case (td:eq(2))
, replace each cell variable z
query?
need create function ajax can pass row index , url contains data query string arguments. since know cell index , once data returned ajax can call fnupdate
using new data , row index within success of ajax
var cells = []; var rows = otable.fngetnodes(); (var = 0; < rows.length; i++) { var grabsku = $j(rows[i]).find('td:eq(3)').text(); grabsku = grabsku.substring(0, 6) + "-0" + grabsku.substring(7, grabsku.length - 4); s7url = 'http://jsonquery.com/' + grabsku + '?req=exists,json'; var rowindex = i; doajax(s7url, rowindex) } function doajax(url, rowindex) { $j.ajax({ url: s7url, datatype: 'jsonp', success: function(repsonse) { var s7img = sku; s7img = '<img src="http://imageserver.com/is/image/' + s7img.substring(0, 6) + "-0" + s7img.substring(7, s7img.length - 4) + '">'; x = response["catalogrecord.exists"]; z = x == "0" ? "no img" : s7img; console.log(z); /* fnupdate here using new data , rowindex , know cell index already*/ } }); }
Comments
Post a Comment