sakada68
Новичок
Добрый день!
Помогите, у меня ajax не возвращает json данные
sample.js
index.php
Помогите, у меня ajax не возвращает json данные
sample.js
Код:
$(function() {
$.ajax({
type: "GET",
dataType: 'json',
url: "/residents/index.php",
success:function(data){
console.debug(data);
console.debug(data);
alert(data);
}
}).done(function(resident) {
resident.unshift({ id: "0", name: "" });
$("#jsGrid").jsGrid({
height: "70%",
width: "100%",//100%
selecting: true,
filtering: true,
editing: true,
sorting: false,
paging: true,
autoload: true,
pageSize: 15,
pageButtonCount: 5,
controller: {
loadData: function(filter) {
return $.ajax({
type: "GET",
url: "/residents/",
data: filter
});
},
insertItem: function(item) {
return $.ajax({
type: "POST",
url: "/residents/",
data: item
});
},
updateItem: function(item) {
return $.ajax({
type: "PUT",
url: "/residents/",
data: item
});
},
deleteItem: function(item) {
return $.ajax({
type: "DELETE",
url: "/residents/",
data: item
});
}
},
fields: [
{ name: "id", title: "id", type: "text", width: 150 },
{ name: "county", title: "Округ", type: "number", width: 50, filtering: false },
{ name: "dvk", title: "ДВК", type: "text", width: 200 },
{ name: "surname", type: "text", title: "Is Married", filtering: false },
{ type: "control" }
]
});
});//
});
Код:
<?php
include "../models/ResidentsRepository.php";
$config = include("../db/config.php");
$db = new PDO($config["db"], $config["username"], $config["password"]);
$residents = new ResidentsRepository($db);
switch($_SERVER["REQUEST_METHOD"]) {
case "GET":
$result = $residents->getAllNo();
break;
case "POST":
$result = $residents->insert(array(
"name" => $_POST["name"],
"age" => intval($_POST["age"]),
"address" => $_POST["address"],
"married" => $_POST["married"] === "true" ? 1 : 0,
"country_id" => intval($_POST["country_id"])
));
break;
case "PUT":
parse_str(file_get_contents("php://input"), $_PUT);
$result = $residents->update(array(
"id" => intval($_PUT["id"]),
"name" => $_PUT["name"],
"age" => intval($_PUT["age"]),
"address" => $_PUT["address"],
"married" => $_PUT["married"] === "true" ? 1 : 0,
"country_id" => intval($_PUT["country_id"])
));
break;
case "DELETE":
parse_str(file_get_contents("php://input"), $_DELETE);
$result = $residents->remove(intval($_DELETE["id"]));
break;
}
header('Content-Type: application/json; charset=utf-8');
//echo json_encode($result);
echo "Now the json encoded result: \n";
echo json_encode($result);
//var_dump($result);
//phpinfo(32);
?>
Последнее редактирование: