0

I am trying to grab data from php

This is my function in 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;
}

So I did the following at my 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");

The problem is that nothing happens when I run it.

I want to able get the return result of my php, and then set

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

Is there anything that I am doing wrong?

smottt
  • 3,272
  • 11
  • 37
  • 44
BUN
  • 57
  • 8

1 Answers1

0

Have you tested your PHP if you get in function getEvent($eventId) at all?

Also double check that you are passing the $_POST['value'] to $eventId

Your javascript are expecting a json back from the PHP, so in your PHP you need to print the return result as a json, are you doing that somewhere? ex echo json_encode($ret);

JimboSlice
  • 692
  • 4
  • 13