Hello stackoverflow nation ! I've such a snag. Trying to pass in jqGrid array data which is retrieved within ajax, but it doesn't work. lets take a look at script =>
$(function(){ // this script works just fine (of course this array and jqGrid initialization script is in the same file)
var arr = [
{a:"a",b:"b"},
{a:"c",b:"d"}
];
$("#_tb").jqGrid({
datatype: "local",
data: arr,
colNames: ["ONE","Two"],
colModel: [
{name:"a",index:"a",align:"center"},
{name:"b",index:"b",align:"center"}
],
pager: $("#_pager"),
height: "auto"
});
});
here is my problem =>
$.ajax({
url: "../info.php",
type: "get",
data: {},
success: function(r){
$("#_tb").jqGrid({
datatype: "local",
data: r,
colNames: ["ONE","Two"],
colModel: [
{name:"a",index:"a",align:"center"},
{name:"b",index:"b",align:"center"}
],
pager: $("#_pager"),
height: "auto"
});
}
});
this script doesn't work , but data is successfully retrieved within ajax into json format.
here is info.php
script by the way too
// using PDO for connection
foreach($con->query("SELECT * FROM tb") as $row){
$info[] = array(
"a" => $row["a"],
"b" => $row["b"]
);
}
echo json_encode($info);
PS. In my opinion my problem is connected to datatype , but can't made up my mind how to solve that despite of searching examples like that . Also remarkable is that I want datatype to be local , because of searching and filtering data in jqGrid without any SQL where statements. With any advice I'll be pleased , thanks :)