Сообщение от Poznakomlus
|
//здесь можно в любой удобной тебе конструкции, массив, объект(в примере), можно и простой строкой
$result = new stdClass();
$result->x='x';
$result->id='id';
die(json_encode($result));
//так отдаешь php
//так обрабатываешь
success: function (json) {
console.log(json);
console.log(json.x);
console.log(json.id);
},
|
console.log(json); // {"x":"x","id":"id"}
console.log(json.x);// undefined
console.log(json.id);//undefined
Сообщение от Rise
|
javascript:
$.post("script.php", { x: x, id: id }, onAjaxSuccess, "json");
function onAjaxSuccess(data) {
// data.x
// data.id
}
php:
if(isset($_POST['x'], $_POST['id'])) {
// ...
// запрос к базе
// ...
$response['x'] = 'Значение x';
$response['id'] = 'Значение id';
echo json_encode($response);
}
|
Сработало, спасибо! То, что я и хотел.