I placed an fwrite statement in ajaxfcn1() and it is writing to file.
So I'm getting as far as triggering ajaxfcn1 now. But the div isn't
updating.
I guess what I am having trouble understanding is how CakePHP
generates a response to the asynchronous call. With the standard
javascript XMLhttprequest object, the server-side php usually
generates an xml response containing the desired data to be is sent
back to the client.
eg. something like this:
===============
<?php
$data = "this is a test";
// we'll generate XML output
header('Content-Type: text/xml');
// generate XML header
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
// create the <response> element
echo '<response>';
//
echo $data;
// close the <response> element
echo '</response>';
?>
=================
then you can use $data on the client side javascript, for example
placing it in a <div> element.
I understand that this is abstracted out in CakePHP, but I am having a
hard time understanding the process conceptually. In CakePHP how is
this xml data generated? (how do I place data in the response to be
passed back to the client)? And how do I update divs with it? (without
having access to js functions like
document.getElementById("divout").innerHTML). thanks
On Sep 30, 9:07 am, Donkeybob <rip...@gmail.com> wrote:
> it looks like your syntax is wrong for the ajax link . . .no
> parenthesis around '$ajax->link' code either . . .check outhttp://book.cakephp.org/view/212/Methodsfor proper syntax.
>
> from the manual related to your code
> <?php echo $ajax->link('View Post',
> array( 'controller' => 'tests', 'action' => 'ajaxfcn1', 1 ),
> array( 'update' => 'divout', 'complete' => 'alert( "Executed
> OK" )' )
> );
> ?>
>
> in your controller function:
>
> echo "Controller Executed";
>
> as long as protoptype is linked up, then that should work.
>
> On Sep 29, 11:56 pm, qwanta <rgmic...@gmail.com> wrote:
>
> > Hi,
> > I have been struggling a bit to get a simple Ajax link working. I have
> > searched this group for help in older posts, but it seems like a key
> > tutorial (the grahambird one) is no longer available - perhaps because
> > it no longer works with 1.2.
>
> > If there is a tutorial somewhere that covers this, please let me know.
> > I think I have gone over all the available (through google) CakePHP
> > ajax tutorials, but unfortunately without success - some are outdated
> > (pre 1.2), others do not have full working code etc...
>
> > In any case, here is my code:
> > ========================================
> > index.ctp
> > <h2>Ajax 3 - testing ajax link and button</h2>
> > <?php
> > $link_array1 = array('controller'=>'tests' ,
> > 'action'=>'ajaxfcn1'); // the function to execute: function
> > ajaxfcn1 in controller tests
>
> > $link_array2 = array( 'update' => 'divout',
> > 'complete' => 'alert( "Executed OK" )' ); // the div we want
> > to update
>
> > echo ($ajax->link('this an ajax link', $link_array1,
> > $link_array2,'Confirmation String'));
>
> > echo "<br/><br/>";
>
> > echo ($ajax->submit('this is an ajax button', $link_array1,
> > $link_array2,'Confirmation String'));
> > ?>
> > <br/>
> > <div id="divout">
> > the div to update
> > </div>
> > ========================================
> > tests_controller.php
> > <?php
> > class TestsController extends AppController {
>
> > var $name = 'Tests';
> > var $uses = array(); // prevent cake from looking for a database
> > model
>
> > function index() {
>
> > }
>
> > function ajaxfcn1() {
> > $this->render('index', 'ajax');
> > }}
>
> > ?>
> > ========================================
>
> > So basically I have a view with an ajax link, an ajax button, and a
> > <div>. I would like to change the text in the div when I click the
> > link or button. At this point, nothing happens when I click them. I am
> > not sure if the ajaxfcn1() function is even executing at this point.
> > What's an easy statement to add in ajaxfcn1() to determine if the code
> > is executing? What function would I use to set the new div text from
> > within ajaxfcn1()?
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment