Thursday, December 30, 2010

Re: Js (Jquery) Helper Confirm before Request

Fantastic! It's a tad different. With the Js helper, it's 'before' not
'beforeSend' and I don't need the function in the before code, just
'return confirm("are you sure?");'.

But you were pretty close considering you don't even use the Js
Helper.

Thank you so much!

On Dec 30, 6:28 pm, cricket <zijn.digi...@gmail.com> wrote:
> On Thu, Dec 30, 2010 at 4:35 PM, Eric Anderson
>
>
>
>
>
>
>
>
>
> <andersoneric...@gmail.com> wrote:
> > Hi everyone,
>
> > I'm trying to use the Js Helper (JQuery) to create a request link that
> > when clicked, confirms before sending the request. If "cancel" in the
> > dialog is clicked, then the request is NOT sent.
>
> > This is what I have so far:
>
> > *CODE*
>
> > <a href="#" class="delete-post-link">Delete Post</a>
>
> >    <?php
> >        $this->Js->get('#post-'.$post['Post']['id'].' .delete-post-
> > link')->event('click',
> >        $this->Js->request(array(
> >        'controller' => 'posts', 'action' => 'delete', $post['Post']
> > ['id']), array(
> >        'async' => true,
> >        'success' => '$("#post-'.$post['Post']['id'].', #post-'.
> > $post['Post']['id'].'-list").fadeOut();')));
> >    ?>
>
> > *ENDCODE*
>
> > So, this ensures that the anchor above is turned into an AJAX link
> > that sends a request to delete the post I need it to. It even fades
> > out the content after successfully deleting the post. However, I want
> > to have a confirmation dialog appear before sending the request AND if
> > cancel is clicked, the request is NOT sent.
>
> (I don't use JSHelper so I may be wrong here.)
>
> Use the beforeSend callback for $.ajax(). If you return false the
> request is cancelled.
>
> $this->Js->request(
>         array(
>                 ...,
>                 'beforeSend' => 'function(XMLHttpRequest, settings) { return
> confirm("Are you sure about this?"); }'
>         )
> )

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: