In addition, just to prove I am not a complete dope. I get how this works,
just not with CakePHP.

AJAX_TEST.PHP

<?php

$row_count = ($_POST['row_count'] + 1);

echo "<tr id=\"row$row_count\"><td>Content for row $row_count</td></tr>";

?>


AJAX_TEST.HTML

<html>
<head>
<title></title>
<script type="text/javascript" src="javascript/jquery-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
        $('#button').click(function()
        {
                $.ajax({
                        url: 'ajax_test.php',
                        type: 'POST',
                        data: "row_count=" +
document.getElementById('mytable').rows.length,
                        dataType: 'html',
                        timeout: 2000,
                        error: function(XMLHttpRequest, textStatus,
errorThrown)
                        {
                                // ...
                                alert('There has been an error');
                        },
                        success: function(msg)
                        {
                                //alert(msg);
                                $('#mytable').append(msg);
                        }
                }); // ends ajax
        }); // ends click 
}); // ends document.ready
</script>
<head>
<body>

<table id="mytable">
        <tr id="row1"> 
                <td>Content for row 1</td>
        </tr>
</table>

<div id="button">Click</div>

</body>
</html> 

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of rhythmicde...@gmail.com
Sent: Saturday, January 03, 2009 9:45 PM
To: CakePHP
Subject: Re: Adding table row with AJAX


Hi Brian,
I was wondering if you had an answer to this issue I am having. I dont
understand the error, or why the data is not appending.

Thanks.



On Jan 3, 9:43 am, Steven Wright <rhythmicde...@gmail.com> wrote:
> Thanks for the reply. This is mostly working but there is something I 
> am still missing.
>
> I tried two different things.
>
> 1) If I call the 'edit' action I get a jQuery error ( 'div is null' ' 
> elem = jQuery.makeArray( div.childNodes ); ') I am not sure what div 
> its looking for. The second problem with that is that although I can 
> see thetablerowreturned at the start of the response string the rest 
> of the content for the view is also returned and I don't know why.
>
> 2) If I call the 'add_ingredient_row' action I only get the content 
> for the view in the response but no newrow.
>
> So two questions:
> 1) Why is CakePHP returning all the content for the view?
> 2) Why is jQuery giving me that error?
>
> Thanks again. If I can just get over this hurdle I will be off and
running.
>
> VIEW
>
> <h2>Testing AJAX with CakePHP and Prototype and Scriptaculous</h2>
>
> <tableid="the_table">
>         <tr id="row1">
>                 <td>Row1</td>
>         </tr>
> </table>
>
> <div id="mydiv">
> This is a div
> </div>
>
> <div id="the_button">Click</div>
>
> CONTROLLER
>
> class AjaxtestsController extends AppController {
>
>         var $components = array( 'RequestHandler' );
>
>         function index()
>         {
>                 $this->pageTitle = 'Index Page';
>         }
>
>         function view()
>         {
>                 $this->pageTitle = 'View Page';
>         }
>
>         function edit()
>         {
>                 $this->pageTitle = 'Edit Page';
>                 if($this->RequestHandler->isAjax())
>                 {
>                         $this->layout = 'ajax';
>                         echo '<tr><td>This is arow</td></tr>';
>
>                 }
>         }
>
>         function add_ingredient_row()
>         {
>                 echo '<tr><td>This is arow</td></tr>';
>
>         }
>
> }
>
> JAVASCRIPT
>
> $(document).ready(function()
> {
>         $('#the_button').click(function()
>         {
>                 $.ajax({
>                         url: 'add_ingredient_row/',
>                         type: 'GET',
>                         data: 'data string',
>                         dataType: 'html',
>                         timeout: 2000,
>                         error: function(XMLHttpRequest, textStatus,
> errorThrown)
>                         {
>                                 // ...
>                                 alert('There has been an error');
>                         },
>                         success: function(msg)
>                         {
>                                 //alert(msg);
>                                 $('#the_table').append(msg);
>                         }
>                 }); // ends ajax
>         }); // ends click
>
> }); // ends document.ready
> -----Original Message-----
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
> Behalf
>
> Of brian
> Sent: Friday, January 02, 2009 8:26 PM
> To: cake-php@googlegroups.com
> Subject: Re:Addingtablerowwith AJAX
>
> On Fri, Jan 2, 2009 at 7:45 PM, Steven Wright 
> <rhythmicde...@gmail.com>
> wrote:
>
> > Hi Adam,
> > Thanks for writing back. How would you get the data back for therow 
> > from CakePHP?
>
> > Myrowcontains four columns with the following inputs:
>
> > amount [text]
> > measurement_type [select]
> > description [text]
> > ingredient [select]
>
> > This is normally rendered from an element as atablerow. I would like 
> > the output of that element appended to mytable.  So on the button 
> > click I call the action add_ingredient_row and it should return the 
> > content of the element. How do I get that content appended to mytable.
>
> > I can do this without CakePHP. But for me this exercise is to use 
> > the framework.
>
> Being a jQuery user, I never bother with Cake's ajax() stuff. But 
> jQuery is dead simple (mostly) to use, so I don't mind having to write 
> out a few lines of JS. To do what you describe, I'd do something like
> this:
>
> $(document).ready()
> {
>         $('#the_button').click(function()
>         {
>                 $.ajax({
>                         url: the_href,
>                         type: 'GET',
>                         data: the_data,
>                         dataType: 'html',
>                         timeout: 2000,
>                         error: function(XMLHttpRequest, textStatus,
> errorThrown)
>                         {
>                                 // ...
>                         },
>                         success: function(msg)
>                         {
>                                 /* assuming your controller is 
> returning '<tr>...</tr>'
>                                  */
>                                 $('#the_table').append(msg);
>                         }
>                 });
>         });
> });


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to