Jqueryajax returns a two-dimensional array, online, etc. below is the ajax page where I return a string
Page
$ (Document). ready (function (){
$ ("#1"). keyup (function (){
$. Post ("action. php ", {n1: $ (" #1 "). val (), n2: $("#1 "). val ()}, function (result ){
Alert (result)
});
});
});
Action. php page
$ Txt = $ _ POST ['n1 '];
Echo 'This sw from page B, input is '. $ txt. $ _ POST ['n2'];
?>
Question: Now we need to get a php two-dimensional array through the action. php page. on page a, we can use alert to generate a js two-dimensional array. how should we implement it? (test data can be used for answers) thanks
Reply to discussion (solution)
The result of alert (two-dimensional array) is array.
Data in json format can be returned.
After interaction with JS, try to use json data format.
Php can directly use the function to output the json content.
$ (Document). ready (function (){
$ ("#1"). keyup (function (){
$. Post ("action. php ", {n1: $ (" #1 "). val (), n2: $("#1 "). val ()}, function (result ){
Alert (result. n1 + ''+ result. n2 );
}, 'Json ');
});
});
Action. php page
$ Txt = $ _ POST ['n1 '];
Echo json_encoding (array ('n1 '= >$ _ POST ['n1'], 'n2 '= >$ _ POST ['n2']);
Exit;
?>
echo json_encode(array(array('a'=>'b'),array('c'=>'d')));
alert(result[0][a]);
Not tested. it should be like this.
Php + jquery + ajax + json example