[solved] ajaxButton not escaping ajax options

I've created an ajax button:

CHtml::ajaxButton('Save New Customer', array('/user/create'), array('type'=>'POST','success'=>'newCustomerFormResult'))

However, the html output doesn't escape the 'success' value:


Of course, JS sees 'newCustomerFormResult' as a variable and not a callback function.

Is my syntax off?


check your url, I think that should be array('user/create').

Thanks for your quick reply!

After excising the leading slash from the url, the html output still hasn't changed:


Any more ideas?


if you want change html you can use update parameter from ajaxOptions array. And I think that if you want submit form you should use ajaxSubmitButton http://www.yiiframew…itButton-detail

Sorry, I updated my code since my first post and tried to use ajaxSubmitButton:

CHtml::ajaxSubmitButton('Save New Customer', array('user/create'), array('success'=>'newCustomerFormResult'), array('name'=>'submitUser'))

No change.

I did use the replace/update options at first, but I've decided to use a callback function on success instead. I need to do several things like replace a div with a message and refresh a dropdown list. Hence, the need for the 'newCustomerFormResult' callback function.

Maybe your action generate error? Check your action without ajax request.

According to Jquerry documentation the code generated is ok. 'success' parameter shouldn't be a string but a function.

$(document).ready(function() {});

 $("a").click(function() {});


   url: "someurl.php",

   success: function() {}


Just try to alter your php array to:


for more info check


click on options and scroll down to success.

Hope that helps.


Whilst I was offline, I managed to discover that yes, I was confusing my php with JS. ajaxSubmitButton works fine like so:

CHtml::ajaxSubmitButton('Save New Customer', array('user/create'), array('success'=>newCustomerFormResult), array('name'=>'submitUser'))


Thanks for your responses!