Ajax callback function not called with ajaxSubmitButton

I can’t get a CHtml::ajaxSubmitButton to do the callback on success/error/beforeSend/complete.

Here is the code I’m using for testing purpose within my view:


echo CHtml::beginForm();

echo CHtml::textField('My label', 'my value');

$options = array(

 'beforeSend' => 'js:function(XMLHttpRequest) { alert("before send"); }',

 'success' => 'js:function(data, textStatus, XMLHttpRequest) { alert("success"); }',

 'error' => 'js:function(XMLHttpRequest, textStatus, errorThrown) { alert("error"); }',

 'complete' => 'js:function(XMLHttpRequest, textStatus, errorThrown) { alert("complete"); }'


echo CHtml::ajaxSubmitButton('Ajax submit button', CHtml::normalizeUrl(array('controller/action'), $options));

echo CHtml::ajaxButton('Ajax button', CHtml::normalizeUrl(array('controller/action')), $options);

echo CHtml::ajaxLink('Ajax button', CHtml::normalizeUrl(array('controller/action')), $options);

echo CHtml::endForm();


It does work as expected for ajaxButton and ajaxLink but NOT for ajaxSubmitButton.

Has anyone encountered this issue before? Any solution?

Thanks for your time.

It is because your normalizeUrl for the ajax submit button bracket is not closed. By the way, you just have to put array(‘controller/action’) instead of CHtml::normalizeUrl(array(‘controller/action’)).

You well spotted the unclosed (closed later actually) bracket.

Thanks for the tips about the unnecessary normalizeUrl call.

Thanks for your time.