Reputation: 1687
I am using data that's in a csv file to display it using JSON. I can see it in the alert, but not in the html. Also, I tried to create an associative array to make it easier to refer to through Jquery, but it's not being passed that way.
<?php
if (($handle = fopen('upload/05-22-2012-1-43-28BEN-new.csv'. '', "r")) !== FALSE) {
while (($row_array = fgetcsv($handle, 1024, ","))) {
while ($val != '') {
foreach ($row_array as $key => $val) {
$row_array[] = array_combine($key, trim(str_replace('"', '', $val)));
}
}
$complete[] = $row_array;
//print_r($row_array);
}
fclose($handle);
}
echo json_encode($complete);
?>
HTML
<body>
<div id="showdata"></div>
</body>
JQuery
$(document).ready(function(){
$.getJSON('WF-XML.php', function(data) {
alert(data); //uncomment this for debug
//alert (data.item1+" "+data.item2+" "+data.item3); //further debug
$('#showdata').html(data);
});
});
Results
[["11704","1611704","BENV1072"],["11703","1611703","BENV1073"]]
Upvotes: 0
Views: 92
Reputation: 3026
First of all you need to stringify your object using JSON.stringify, also .html() method does not escape the string - try using .text() instead.
I've created a simple fiddle for testing - http://jsfiddle.net/E9KTy/
Upvotes: 1