Monday, December 17, 2012

Re: cakephp and ajax

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

No comments: