jquery - How to pass parameters to php using get JSON -
i have json_data.php
file , want pass parameter function inside switch statement using getjson
.
<?php require_once "db.php"; $db = new db(); if(isset($_get['method'])) { switch (($_get['method'])) { case 'getuserids': echo json_encode($db -> getuserids()); exit(); case 'getuser': echo json_encode($db -> getuser($userid) { exit(); // other cases go here case 'getcertcategories': echo json_encode($db -> getcertcategories()); exit(); case 'get default: break; } }
how pass parameter can pass $userid
getuser
function?
the second argument $.getjson
object containing query parameters.
$.getjson('json_data.php', { method: 'getuserids' }, function(response) { ... }); $.getjson('json_data.php', { method: 'getuser', userid: 'joe' }, function(response) { ... });
in php, access $_get['method']
, $_get['userid']
, etc.
Comments
Post a Comment