Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用get JSON将参数传递给php_Php_Jquery_Json - Fatal编程技术网

如何使用get JSON将参数传递给php

如何使用get JSON将参数传递给php,php,jquery,json,Php,Jquery,Json,我有一个json_data.php文件,我想使用getJSON将参数传递给switch语句中的函数 <?php require_once "Db.php"; $db = new Db(); if(isset($_GET['method'])) { switch (($_GET['method'])) { case 'getUserIds': echo json_encode($db -> getUserIds());

我有一个
json_data.php
文件,我想使用
getJSON
将参数传递给switch语句中的函数

<?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;
    }

 }

第二个参数是包含查询参数的对象

$.getJSON('json_data.php', { method: 'getUserIds' }, function(response) {
    ...
});

$.getJSON('json_data.php', { method: 'getUser', userId: 'joe' }, function(response) {
    ...
});

在PHP中,您可以访问
$\u GET['method']
$\u GET['userId']
,等等。

getUser()附近出现语法错误。
。。。