Monday, December 21, 2009

Ajax with JSON returned from response (Prototype)

Javascript code:
----------------
edit_info = function(id) {
url = 'www.test.com/get_info?id=' + id;
new Ajax.Request(url, {
method: 'post',
onComplete: function(req) {
var data = eval("("+req.responseText+")");
$('email').value = data['email'];
$('city').value = data['city'];
}
});
}

PHP code:
---------
public function get_info() {
$info = db.query('select * from info where id='.$_REQUEST['id']);
echo json_encode($info);
exit;
}

No comments:

Post a Comment