Javascript 和 PHP 数据馈送使用情况

Javascript and PHP Data Feed Usage

我正在尝试从 php 中获取数据

这是我在 php 中的函数

function getEvent($eventId){
  $ret = array();
  $ret['events'] = array();
  try{
    $db = new DBConnection();
    $db->getConnection();
    $sql = "select a.contact_name,a.userid from `contact` a where a.Id='$eventId'";
    $handle = mysql_query($sql);
    while ($row = mysql_fetch_object($handle)) {
      //$ret['events'][] = $row;
      $ret['events'][] = array(
        $row->contact_name,
        $row->userid
      );
    }
    }catch(Exception $e){
     $ret['error'] = $e->getMessage();
  }
  return $ret;
}

所以我在我的 javascript 中做了以下操作

var eventId = '2';
var DATA_FEED_URL =  "datafetcher.php";
var param = [{ "name": "eventId", value: 9}];                
$.post(DATA_FEED_URL + "?method=getEvent",
    param,
    function(data){
          if (data.IsSuccess) {
                alert(data.Msg); 
                //CloseModelWindow(null,true);                            
            }
            else {
                alert("Error occurs.\r\n" + data.Msg);
            }
    }
,"json");

问题是当我运行它时没有任何反应。

我希望能够得到我的 php 的 return 结果,然后设置

var contactName = Return Result contact name element under the $ret array from the datafeed
var contactId = Return result contact id element under the $ret array from the datafeed

我做错了什么吗?

您是否测试过您的 PHP 是否完全进入 getEvent($eventId) 功能?

还要仔细检查您是否将 $_POST['value'] 传递给 $eventId

您的 javascript 期待 PHP 返回 json,因此在您的 PHP 中,您需要将 return 结果打印为 json,你在某个地方这样做吗? 例如 echo json_encode($ret);