Jump to content

how to use jquery with ajax to get data ? (on Zend )


avibitton

Recommended Posts

Hi

 

im working on zend framework , i want to get data from database using ajax , than use it for diffrente function of javascript , but i dont know how to use it , and i dont know if i need to open new php page for using the ajax and get methood , how to use the jquery with ajax to get data ?. is it possible also to use jquery with ajax as it is or i need differnte command in zend ?

 

Thx avi.

there are a few choices available to you in the framework:

1) create an aync / ajax controller :

 

you can create an ajax conroller, and in the init method of the controller you disable the view from rendering using:

public function init()
{
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
}

then an example method you will call could be  /MyajaxController/getmyinfo/var1

 

public function getmyinfoAction(){
$result = (database array or whatever);//array - stuff from database
echo json_encode($result);


}

 

2) read up on zend frameworks context switching. this is the preferable method, as you wont then need a specific ajax controller. the context switching allows you to use your normal controllers, and basically says ' if this call is ajax then return json etc......

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.