Thanks for taking your time.

Yes the click-handler works.
I controll this by outputting the storeID.

  jQuery('#storeListTable tr').click(function() {

    var storeID = this.cells[0].innerHTML;
    alert(storeID);  // storeID for clicked row is aoutputed.

    jQuery.post("../get_storeData.php", { sID: storeID },
      function(data){
         alert(data.name);
      }, "json");
    });

WOHO. Alright. SOMETHING is happening.

I removed my function so that I only have my PHP code in the new file
I call get_storeData.php.
Now the get_storeData.php file looks like this:

<?php
  include_once('dal.php');

  $storeID = "9";//$_GET["storeID"];

  $sl = new storeLocator();
  $result = $sl->getStoreData($storeID);

  while ($row = mysql_fetch_assoc($result))
  {
      $arr[] = $row;
  }
  $storeData = json_encode($arr);
  echo $storeData;
?>

Clicking a row now, gives me an alert, but it's 'Undefined'.
If I change "alert(data.name);" to "alert(data);", I get the following
output: "[object Object]".

I'm soooo close now. What am I missing?


Ps. If I change    "(...) "json");" to "(...)  "text");" and only have
echo "TEST" in my php file, the "TEST" will be aouputed in the alert.

Steven



On 16 Apr, 14:35, Josch <jluelsd...@googlemail.com> wrote:
> 1. Some questions :-)
> The click-Handler works?
> The post is triggered?
>
> 2. You can't call a function just with func: getStoreInformation.
> You could use your "func: getStoreInformation" on Javascript,
> but then you have to do something like
>
> $func = $_POST['func'];
> $storeID = $_POST['sID'];
> call_user_func ($func, $storeID); // Not sure about the syntax here,
> but something like that
>
> ..because "func" is just another parameter for PHP.
>
> 3. Yes, you can use sID: storeID
>
> Greets, Josch
>
> On 16 Apr., 14:21, spstieng <spsti...@hotmail.com> wrote:
>
>
>
> > No, I don't get alert. That means it's failing silently.
>
> > I've tested the functions.php (by running it) and it ouputs the data
> > in JSON format.
> > So retrieveing and echo'ing the data works fine.
>
> > It's the jQuery that I got wrong.
>
> > 1. How do I call a specific funtion within functions.php? I got a "bad
> > feeling" that  func: "getStoreInformation" is just an input parameter
> > and has nothing to do with calling the function getSToreInformation().
> > 2. I need to pass the storeID. I get this with the folloing line: "var
> > storeID = this.cells[0].innerHTML;".
> > I guess I should pass it as parameter:   jQuery.post("../
> > functions.php", { func: "getStoreInformation", sID: storeID  }
> > But I don't think I can use " sID: storeID ".
>
> > Steven
>
> > On 16 Apr, 14:13, Josch <jluelsd...@googlemail.com> wrote:
>
> > > Do you get an empty alert or nothing?
>
> > > On 16 Apr., 12:13, spstieng <spsti...@hotmail.com> wrote:
>
> > > > Hi, I'm trying to use jQuery.post() function to retrieve som data. But
> > > > i get no ouput.
>
> > > > My PHP file looks like this:
>
> > > > <?php
> > > >   inlcude_once('dal.php');
>
> > > >   //Get store data, and ouput it as JSON.
> > > >   function getStoreInformation($storeID)
> > > >   {
> > > >     $sl = new storeLocator();
> > > >     $result = $sl->getStoreData($storeID);
>
> > > >     while ($row = mysqli_fetch_assoc($result)) {
> > > >     {
> > > >         $arr[] = $row;
> > > >     }
> > > >     $storeData = json_encode($arr);
> > > >     echo $storeData;  //Output JSON data
> > > >   }
> > > > ?>
>
> > > > This is my javascript which is located in /js/myscripts.js
>
> > > > jQuery(document).ready(function() {
> > > >   jQuery('#storeListTable tr').click(function() {
> > > >     jQuery.post("../functions.php", { func: "getStoreInformation" },
> > > >     function(data){
> > > >        alert(data.name); // To test if I get any output
> > > >        //$('#store_name').val(data.name);   // I could do this to
> > > > populate my form
> > > >       //$(#store_data_form).populate(data, {debug:1})  //But I
> > > > probably will use jQuery "Populate" plugin instead
> > > >     }, "json");
> > > >   });
>
> > > > });
>
> > > > If this is working, I should be able to get an alert message, right?

Reply via email to