Есть код
$(".send-id-form").submit(function(){
var data = {
"action": "test"
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "../modules/configurate/json.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
$(".test-ajax-js").html(
"Favorite beverage: " + data["Name"] + "<br />Favorite restaurant: " + data["Descrpition"] + "<br />Gender: " + data["id"]
);
console.log("Form submitted successfully.\nReturned json: " + data["json"]);
}
});
return false;
});
И php
if (is_ajax()) {
if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
$action = $_POST["action"];
switch($action) { //Switch case for value of action
case "test": test_function(); break;
}
}
}
//Function to check if the request is an AJAX request
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}
function test_function(){
$id = $_POST['id_edit_now'];
$data = array();
$send = mysql_query("SELECT * FROM structure WHERE id = '$id'");
while($row = mysql_fetch_assoc($send)){
$data[] = $row;
}
echo json_encode($data);
}
В общем не догоняю как вывести как в php mysql_fetch_assoc, только json - data["тут имя поля"]