Wednesday, May 2, 2012

Re: Problem with JsHelper

You need to switch these two around:
<?php 
class Controller extends AppController { 
}  



On Wednesday, February 15, 2012 7:47:50 AM UTC-5, Diablo Sinfuego wrote:
I have a problem with Js that I cannot resolve. I am basically trying
to write a "Hello, world" app to learn how to use this feature.

When I click on my submit button the first time, everything works.
When I click on the same button the second time, it blows up trying to
go to what appears to be a "null" controller:

Missing Controller
Error: Controller could not be found.
Error: Create the class Controller below in file: app/Controller/
Controller.php
<?php
class Controller extends AppController {
}

Here is my Controller:

public function check($id = false) {
                if (!empty($this->request->data)) {
                        if ($this->RequestHandler->isAjax()) {
                                $this->set('result', 'Hello, world');
                                $this->render('result', 'ajax');
                        }
                }
        }

Here is my View:

<?php echo $this->Html->script('jquery', array('inline' => false)); ?>
<?php
        echo $this->Form->create();
        echo $this->Js->submit('Check', array('update' =>
'#success'));
        echo $this->Form->end();
?>
<div id="success"></div>
<div id="checking" style="display: none;">Checking...</div>
<?php echo $this->Js->writeBuffer(); ?>

JsHelper is generating the following JavaScript:

script type="text/javascript">
//<![CDATA[
$("#submit-549405557").bind("click", function (event) {$.ajax({data:$
("#submit-549405557").closest("form").serialize(), dataType:"html",
success:function (data, textStatus) {$("#success").html(data);},
type:"post", url:"\/hosts\/check"});
return false;});
//]]>
</script>

I'm stumped why it works on the first click but not the second.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate