Re: Ajax

Jim Giner <[email protected]>
Newsgroups gmane.comp.php.database
Message-ID <[email protected]>
On 2/20/2013 7:27 PM, Ethan Rosenberg, PhD wrote:
> Dear List -
>
> I think we have to revisit this.
>
> The object is to click on an element of a table [name field] and
> retrieve the customer number[number field] send th eresult as an Ajax
> call to a callback function as a json string, and get back the customer
> number as a PHP variable.
>
> Code snippits:
> Start:
> <div id="e1">
>
> Table:
>
>      $results = "<table border=4 cellpadding=5 cellspacing=55  rules=all
> frame=box style='table-layout:fixed;'>";
>      $results .= "<tr><th>Name</th><th>Number</th></tr>";
>      // generate a table here
>      for($i=0; $i<10; $i++)
>      {
>          $k = $i ;
>          $results .= "<tr><td id='name$i' >$names[$k] </td><td
> id='nums$k'>$nums[$k]</td></tr>";
>
>      }
>      $results = "<table border=4 cellpadding=5 cellspacing=55  rules=all
> frame=box style='table-layout:fixed;'>";
>      $results .= "<tr><th>Name</th><th>Number</th></tr>";
>      }
>      $results .= "</table>";
>      $results;
>
> retrieve number:
>
> <script type="text/javascript">
>      var cusn;
>      $(document).ready(function(){
>          $("#e1").click(function() {
>              cusn = $(this).attr('id');
>              alert(cusn); // this always returns e1
>          });
>      });
> </script>
>
>
>   Ajax Call
>
> <script type="text/javascript">
>      $(document).ready(function(){
>              $("#e1").dblclick(function(e) {
>                   $.post("testClickcallback.php",
>                     {"custnum":cusn},  function getCustNo(id)
>          {
>              cno = 'cust'+id;
>              cnm = "name"+id;
>              cname = document.getElementById(cnm).innerHTML;
>              cnum = document.getElementById(cno).innerHTML;
>          alert("For customer "+cname+" the number is "+cnum);
>              return;
>          }
> //    alert("subval");
>    //alert(subval);
>
>    ,"html");
> });
>
> });
>
> </script>
>
> // receive error: document.getElementById(...) is null
>
> Callback function:
>
> <?php
> $json = Array();
> $json['custnum'] =  $_POST['cusn'];
> echo json_encode($json);
> ?>
>
> //response:
>
> |
> ||Notice: Undefined index: cusn in /var/www/testClickcallback.php on line 5
> ||
> ||Call Stack:
> ||     0.0005     126856   1. {main}() /var/www/testClickcallback.php:0
> ||
> ||
> ||Variables in local scope (#1):
> ||   $json = array ()
> ||
> ||{"custnum":null}
>
> Now what??|||||
>
> Ethan
>
Ethan - you are unbelievable.  I've talked to you about this multiple 
times and thought I had you on the easy path, but you never cease to 
amaze me with your inability to grasp the obvious.

March on.  But without me.  How you make a living in the programming 
world is beyond me.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.