joseluistim Posted January 11, 2014 Share Posted January 11, 2014 Hello. I want to get sql query rows result info through ajax and json. Here´s jquery code: var mod_url = baseDir + '/json_2.php'; var query = $.ajax({ type: 'POST', url: mod_url, dataType: 'json', success: function(comp_arr) { alert(comp_arr); }, error: function (response) { alert(response.responseText); }, }); And here´s php file code : <?php include(dirname(__FILE__).'/../config/config.inc.php'); include(dirname(__FILE__).'/../init.php'); $qr = 'SELECT * FROM '._DB_PREFIX_.'infos_it WHERE infoit=1'; if ($results = Db::getInstance()->ExecuteS($qr)) foreach ($results as $row) { $comp_arr[$i]["id_item"] = $row["id_id_item"]; $comp_arr[$i]["infoit"] = $row["infoit"]; $comp_arr[$i]["icon"] = $row["icon"]; } echo(json_encode($comp_arr)); //return(json_encode($comp_arr)); ?> Jquery Ajax Response is success but null...what I´m doing wrong? Thanks. Link to comment Share on other sites More sharing options...
vekia Posted January 11, 2014 Share Posted January 11, 2014 and what you see if you use var_dump() on $comp_arr variable? Link to comment Share on other sites More sharing options...
joseluistim Posted January 11, 2014 Author Share Posted January 11, 2014 It returns NULL. Link to comment Share on other sites More sharing options...
joseluistim Posted January 11, 2014 Author Share Posted January 11, 2014 More information and tests.. If I execute same query and var_dump directly to database, with $cfg_server= "localhost"; $cfg_database = "xxxx"; $cfg_username = "xxxxx"; $cfg_password = "xxxxx"; instead of Db::getInstance()->ExecuteS($qr), it works correctly and return 19 records with all its fields. Link to comment Share on other sites More sharing options...
joseluistim Posted January 11, 2014 Author Share Posted January 11, 2014 Solved...it was a mistake between table name and DB_PREFIX..now var_dump returns records. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now