jQuery get json_encode variable from PHP -


my php file retrieves data postgresql db. have send them jquery function in 2 different arrays. 1 passed using:

echo json_encode($tb); 

and works fine, in js file data correctly using:

 $.ajax({     type: "post",     url: './db/lb.php',     data: {d_p: oa},     success: function (tb) {       console.log(tb); }) 

console output expected.

the other php array, have replace chars:

str_replace(array('[', ']'), '', htmlspecialchars(json_encode($ltb), ent_noquotes)); 

but if write:

 $.ajax({     type: "post",     url: './db/lb.php',     data: {d_p: oa},     success: function (tb, ltb) {       console.log(tb);       console.log(ltb); }) 

console.log(ltb) outputs

success

what i'm getting wrong?

the second parameter of succes response staus. reason because success when logging tlb.

you can return 1 json @ at time, combine them:

echo json_encode(array("other stuff", "tb" => $tb, "tbl" => array("some" => "data"))); 

on js side can simple acces them index or key:

tb[0];  // "other stuff" tb.tb;  // content of $tb variable tb.tbl; // {some: "data"} 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -