I have added one ajax validation for a custom section in magento checkout page as below,
Validation.js :
['validate-otp', 'Please enter valid OTP.', function(v) {
var url = 'customsect/processing/test?code='+v;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(response){
alert(response.responseJSON);
},
onComplete: function(res){
alert("complete");
},
onFailure: function(err){
alert("Error"+err);
}
});
}]
app/code/local/myaddon/customsect/controllers/ProcessingController.php :
public function testAction()
{
$code = $this->getRequest()->getParams('code');
$itemArr = array('res' => $code);
// $data = json_encode($itemArr);
$this->getResponse()->setHeader('Content-type','application/json'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($itemArr));
}
But am getting alert as "null". When i run below url I'm getting the json response displayed.
http://127.0.0.1/mage3/index.php/customsect/processing/test?code=ADXWZ
{"res":{"code":"ADXWZ"}}