cakephp
अजाक्स अनुरोध से निपटने
खोज…
बेसिक CakePHP 2.x उदाहरण
नियंत्रक: नियंत्रक में आपको RequestHandler घटक जोड़ना होगा। यह स्वचालित रूप से अजाक्स अनुरोध का पता लगाने के लिए CakePHP को सक्षम करता है (अधिक जानकारी के लिए देखें: http://book.cakephp.org/2.0/en/core-lbooks/compenders/request-handling.html ):
class YourController extends AppController {
public $components = array('RequestHandler');
//...
public function ajaxCall() {
if($this->request->is('ajax'){
// some code that should be executed
// ...
// variables you want to return
$this->set(compact('firstVariable', 'secondVariable'));
$this->set('_serialize', array('firstVariable', secondVariable))
}
}
कोड देखें (jQuery का उपयोग करके):
<script>
$.ajax({
type: 'POST',
url: '/yourController/ajaxCall',
success: function (result) {
// result is a JSON array of the returned Variables
},
error: function (result){
console.log(result);
}
});
</script>
केकक्सप 2. एएक्स में अजाक्स अनुरोध
एक और तरीका है कि केक में अजाक्स का उपयोग करें। Cakephp खुद को अजाक्स अनुरोध के लिए प्रदान करते हैं। कृपया उदाहरण देखें।
$data = $this->Js->get('#id')->serializeForm(array('isForm' => true, 'inline' => true));
//on click send request to controller and displays response data in view
$this->Js->get('#button-id')->event(
'click', $this->Js->request(
array('controller' => 'Users', 'action' => 'add'), array(
'update' => '#time', // field you wish to update
'data' => $data, // Form Data in serialize form
'async' => true,
'dataExpression'=>true,
'method' => 'POST' // method get or post
)
)
);
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow