CakePHP and Ajax request

2013-03-20 Thread Piotr Chabros
Hi

I am currently using ajax in multiple controllers in my application. I 
implemented the ajax functionality using the jQuery supported version.

$.ajax({
url:'getCountries',
type: "POST",
dataType: "html",
data:"data=" + result,
success: function(data){
//magic...
}
}
});

As you can see from the code above the url of this request is 
'getCountries'. This means that if the request is made from 
'http://localhost/appname/controllername/methodname' the request url will 
be  'http://localhost/appname/controllername/getCountries'. However if the 
url is different, say 
 'http://localhost/appname/controllername/methodname/7' (like in the edit 
view) or 
( 'http://localhost/appname/controllername/methodname/order:Model.field' 
(like in the pagination) then the request url will dramaticly change to 
 'http://localhost/appname/controllername/methodname/getCountries' in the 
first case and even worse in the second. How can I avoid that?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: cakephp and ajax

2012-12-17 Thread Jonathan Sundquist
Hey David,

You would connect to your model the same way you do within any other
controller.  Your controller code would look something like the following

public function index(){
 // Disable both the view and layout as they both will not be needed.
$this->autoRender = false;
// Make sure someone actually did pass in a discount code
 if($this->request->params['discount_code']){
 // Look up the discount code passed in and then json encode the response
to be used by the ajax handler within the ui.
 echo
json_encode($this->Setting->find(array('conditions'=>array('discount_code'=>$this->request->params['discount_code']);
 }
}

The above code should do about what you want it to.  You will need to write
the remaining code for the UI as I don't know what your fields are named.


On Mon, Dec 17, 2012 at 12:42 AM, David Camerotto wrote:

> Hi, I am relatively new to Cake, I took over a web site that uses it and
> am still learning the ropes, but slowly getting there.
>
> One issue has do have is with the image shown below.
>
> I want to be able to retrieve data from the DB when clicking on the Apply
> link.
>
> I have create a model and controller and have added this code to the click
> event for the link.
>
> $('#go').click(function(){
> $.ajax({
> url:'/discount/index',
> type:'POST',
> data:data
> });
>
> What I'm unsure about is how to retrieve the the data from the DB and how
> to put it into the input box - table is called settings and field is
> discount_code.
>
> Any help would be greatly appreciated
>
>
> 
>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




cakephp and ajax

2012-12-17 Thread David Camerotto


Hi, I am relatively new to Cake, I took over a web site that uses it and am 
still learning the ropes, but slowly getting there.

One issue has do have is with the image shown below.

I want to be able to retrieve data from the DB when clicking on the Apply 
link.

I have create a model and controller and have added this code to the click 
event for the link.

$('#go').click(function(){
$.ajax({
url:'/discount/index',
type:'POST',
data:data
});

What I'm unsure about is how to retrieve the the data from the DB and how 
to put it into the input box - table is called settings and field is 
discount_code.

Any help would be greatly appreciated




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Cakephp and AJAX

2011-12-04 Thread Sebastien Beausoleil
Hi Milos,
Instead of calling an ajax layout, I think you simply should add this
line at the beginning of your action in the controller.

$this->autoRender = false;

This action  will only be executed on the server side.

And to send parameter to the action, why don't you send them in array
by  'post' method in Json encoding and receive the response from the
action the same way.
To do it, use this command:

$this-> Js->request

On 4 déc, 12:05,Miloš Vučinić  wrote:
> Thank you very much !
>
> All the best,
> Milos
>
> On Dec 3, 9:25 am, Tilen Majerle  wrote:
>
>
>
>
>
>
>
> > for response: just create a view like (but not 'default' layout, make a new
> > layout 'ajax') in others functions
>
> > how to detect ajax: $this->request->is('ajax')
>
> > CONTENT FOR ajax.ctp layout:
> > 
>
> > and in controller to enable this layout:
> > $this->layout = 'ajax';
>
> > why this ? this will return just your 'archieve' view
>
> > --
> > Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> > 2011/12/3 Miloš Vučinić 
>
> > > Hello,
>
> > > I haven't used AJAX so far because I never needed it. I read the
> > > manuals regarding it, now I am wondering how to do it in cake. My task
> > > is following:
> > > I have a list of users. Next to each user I have a button which says
> > > archive. On click I have to archive the user. Now, I don want to
> > > reload the whole page so I want to use AJAX.
> > > The way I see it, I would create a regular AJAX call to my url which
> > > is function just like any other in cake, like /users/archive/57 where
> > > number 57 is id in the database (it will be generated for each
> > > button).
> > > On server side I would perform the function, but how do I return
> > > response. Do I just echo it ? And how does the cake knows it was an
> > > AJAX call and that it needs to send a response to a client. And is it
> > > ok, for the response to be just a simple ok , or notok string , and
> > > then if ok, I just change the archive sting into yes from no in the
> > > user list.
>
> > > Can you please give me like quick steps of how would you do it with a
> > > quick syntax example.
>
> > > Like : 1) Create a client call to the server
> > >         2) Execute function on server the normal way you wold
> > >         3) Send response to client (please explain how)
>
> > > Thank you in advance,
>
> > > All the best
> > > Milos Vucinic
>
> > > --
> > > Our newest site for the community: CakePHP Video Tutorials
> > >http://tv.cakephp.org
> > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > > others with their CakePHP related questions.
>
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> > > athttp://groups.google.com/group/cake-php

-- 
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Cakephp and AJAX

2011-12-04 Thread Miloš Vučinić
Thank you very much !

All the best,
Milos

On Dec 3, 9:25 am, Tilen Majerle  wrote:
> for response: just create a view like (but not 'default' layout, make a new
> layout 'ajax') in others functions
>
> how to detect ajax: $this->request->is('ajax')
>
> CONTENT FOR ajax.ctp layout:
> 
>
> and in controller to enable this layout:
> $this->layout = 'ajax';
>
> why this ? this will return just your 'archieve' view
>
> --
> Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> 2011/12/3 Miloš Vučinić 
>
>
>
>
>
>
>
> > Hello,
>
> > I haven't used AJAX so far because I never needed it. I read the
> > manuals regarding it, now I am wondering how to do it in cake. My task
> > is following:
> > I have a list of users. Next to each user I have a button which says
> > archive. On click I have to archive the user. Now, I don want to
> > reload the whole page so I want to use AJAX.
> > The way I see it, I would create a regular AJAX call to my url which
> > is function just like any other in cake, like /users/archive/57 where
> > number 57 is id in the database (it will be generated for each
> > button).
> > On server side I would perform the function, but how do I return
> > response. Do I just echo it ? And how does the cake knows it was an
> > AJAX call and that it needs to send a response to a client. And is it
> > ok, for the response to be just a simple ok , or notok string , and
> > then if ok, I just change the archive sting into yes from no in the
> > user list.
>
> > Can you please give me like quick steps of how would you do it with a
> > quick syntax example.
>
> > Like : 1) Create a client call to the server
> >         2) Execute function on server the normal way you wold
> >         3) Send response to client (please explain how)
>
> > Thank you in advance,
>
> > All the best
> > Milos Vucinic
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php

-- 
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Cakephp and AJAX

2011-12-03 Thread Tilen Majerle
for response: just create a view like (but not 'default' layout, make a new
layout 'ajax') in others functions

how to detect ajax: $this->request->is('ajax')

CONTENT FOR ajax.ctp layout:


and in controller to enable this layout:
$this->layout = 'ajax';

why this ? this will return just your 'archieve' view

--
Lep pozdrav, Tilen Majerle
http://majerle.eu



2011/12/3 Miloš Vučinić 

> Hello,
>
> I haven't used AJAX so far because I never needed it. I read the
> manuals regarding it, now I am wondering how to do it in cake. My task
> is following:
> I have a list of users. Next to each user I have a button which says
> archive. On click I have to archive the user. Now, I don want to
> reload the whole page so I want to use AJAX.
> The way I see it, I would create a regular AJAX call to my url which
> is function just like any other in cake, like /users/archive/57 where
> number 57 is id in the database (it will be generated for each
> button).
> On server side I would perform the function, but how do I return
> response. Do I just echo it ? And how does the cake knows it was an
> AJAX call and that it needs to send a response to a client. And is it
> ok, for the response to be just a simple ok , or notok string , and
> then if ok, I just change the archive sting into yes from no in the
> user list.
>
> Can you please give me like quick steps of how would you do it with a
> quick syntax example.
>
> Like : 1) Create a client call to the server
> 2) Execute function on server the normal way you wold
> 3) Send response to client (please explain how)
>
> Thank you in advance,
>
> All the best
> Milos Vucinic
>
> --
> 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+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Cakephp and AJAX

2011-12-02 Thread Miloš Vučinić
Hello,

I haven't used AJAX so far because I never needed it. I read the
manuals regarding it, now I am wondering how to do it in cake. My task
is following:
I have a list of users. Next to each user I have a button which says
archive. On click I have to archive the user. Now, I don want to
reload the whole page so I want to use AJAX.
The way I see it, I would create a regular AJAX call to my url which
is function just like any other in cake, like /users/archive/57 where
number 57 is id in the database (it will be generated for each
button).
On server side I would perform the function, but how do I return
response. Do I just echo it ? And how does the cake knows it was an
AJAX call and that it needs to send a response to a client. And is it
ok, for the response to be just a simple ok , or notok string , and
then if ok, I just change the archive sting into yes from no in the
user list.

Can you please give me like quick steps of how would you do it with a
quick syntax example.

Like : 1) Create a client call to the server
 2) Execute function on server the normal way you wold
 3) Send response to client (please explain how)

Thank you in advance,

All the best
Milos Vucinic

-- 
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: cakephp and Ajax pagination (mootools)

2010-08-23 Thread Philip Thompson
On Aug 21, 2010, at 3:13 AM, Mariano C. wrote:

> I have followed perfectly this guide (
> http://mark-story.com/posts/view/creating-simple-ajax-pagination-with-cakephp-1-3-and-mootools
> ) but it only works at 50%.
> 
> I just have two link for pagination: 1 & 2. If I go to:
> htp://my_web.com/items/user/page:1 the link to second page is active,
> thus if I click this link the second page will be opened in ajax
> style. OK!
> 
> Now, link for page 2 is disabled and link to the first page is active,
> but, if I click this link the page will be reloaded entirely as normal
> call.
> 
> Viceversa happen if I call htp://my_web.com/items/mariano/page:2.
> Clicking on link 1 will load new page in AJAX, successivly clicking on
> page 2 will happen with classic call.
> 
> Why?

I ran into this same issue. You *must* include your call to $js->writeBuffer() 
within the view that gets rendered with each ajax request. Otherwise, after 
your first click of an ajax link, the new set of links that get loaded from the 
ajax request don't get updated with the custom onclick events.

So, for example, I have a table element that has the option to be shown on each 
ajax request. At the bottom of the element file, I have the appropriate call

writeBuffer(array('onDomReady'=>false));
}
?>

Now, each time the new ajax page loads, the links get updated.

Hope that helps.
~Philip

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


cakephp and Ajax pagination (mootools)

2010-08-21 Thread Mariano C.
I have followed perfectly this guide (
http://mark-story.com/posts/view/creating-simple-ajax-pagination-with-cakephp-1-3-and-mootools
) but it only works at 50%.

I just have two link for pagination: 1 & 2. If I go to:
htp://my_web.com/items/user/page:1 the link to second page is active,
thus if I click this link the second page will be opened in ajax
style. OK!

Now, link for page 2 is disabled and link to the first page is active,
but, if I click this link the page will be reloaded entirely as normal
call.

Viceversa happen if I call htp://my_web.com/items/mariano/page:2.
Clicking on link 1 will load new page in AJAX, successivly clicking on
page 2 will happen with classic call.

Why?

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Firefox error with json.js, cakephp and ajax scriptaculo

2007-04-05 Thread [EMAIL PROTECTED]

Hi,
in my application cakephp I have this code (into view):


echo $javascript->link('prototype');
echo $javascript->link('scriptaculous.js');
echo $javascript->link('json.js');
...
...
...

$options = array("url"=>"/bufferpoints","complete" =>
"prove(request)");
echo $ajax->link('Prova ajax',null,$options);
...
...
 

Re: CakePHP and AJAX 'engines'

2006-08-24 Thread teemow

my love goes to jquery. documentation is currently under
http://proj.jquery.com/, john will hopefully move this to jquery.com
soon.

with jquery you can completly separate your javascript and html. there
is a description in this post:
http://jquery.com/blog/2006/08/20/why-jquerys-philosophy-is-better/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: CakePHP and AJAX 'engines'

2006-08-23 Thread Marcelo de Moraes Serpa
Flash Platform :D (Flash/Flex 2) through CakeAMFPHPOn 8/23/06, Olivier Percebois-Garve <[EMAIL PROTECTED]
> wrote:I love moo.fx. (uses a lite version of prototype)But the most promising theses days is probably jquery. (encapsulates
also a part of moo.fx)mouth wrote:> Hi all,>> which AJAX engines (other then prototype.js) are You successfully using> with CakePHP, guys? Should You please share with us some limits of Your
> solutions?>> I can't help myself, but in cases I need just one little ajax-driven> functionality I don't think I need prototype's obesity.>> Thx, mouth.>>> >
>>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---


Re: CakePHP and AJAX 'engines'

2006-08-23 Thread Olivier Percebois-Garve

I love moo.fx. (uses a lite version of prototype)
But the most promising theses days is probably jquery. (encapsulates 
also a part of moo.fx)

mouth wrote:
> Hi all,
>
> which AJAX engines (other then prototype.js) are You successfully using
> with CakePHP, guys? Should You please share with us some limits of Your
> solutions?
>
> I can't help myself, but in cases I need just one little ajax-driven
> functionality I don't think I need prototype's obesity.
>
> Thx, mouth.
>
>
> >
>
>   


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



CakePHP and AJAX 'engines'

2006-08-23 Thread mouth

Hi all,

which AJAX engines (other then prototype.js) are You successfully using
with CakePHP, guys? Should You please share with us some limits of Your
solutions?

I can't help myself, but in cases I need just one little ajax-driven
functionality I don't think I need prototype's obesity.

Thx, mouth.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---