Hi Guys,
I have an issue with some ajax calls and was hoping for some help with this.
To save pasting huge chunks of code I have a quick example that can be tested to show the issue I am referring to. The issue as shown by the snippets below is as follows. I have a button on the page, Button A. When I click button A and ajax call is made and the returned data, another ajax button, this one called Button B is placed onto the page.
When clicking Button B, I expect it to make another ajax call and alert the respnse. In this case I would expect it to alert "Successful". However, the first ajax call works, but the second does not as it seems the javascript success function etc is not passed for the second button.
Here is the view code:
<?php
echo CHtml::ajaxSubmitButton('Button-A',CHtml::normalizeUrl(array('/Accounts/testAjax')),array('success'=>'function(data)
{
$("#button-test").html(data);
}',
'type'=>'POST'),
array('id'=>'button-a'));
?>
<div id="button-test"></div>
Here is the controller code:
public function actiontestAjax()
{
echo CHtml::ajaxSubmitButton('Button-B',CHtml::normalizeUrl(array('/Accounts/testAjax2')),array('success'=>'function(data)
{
alert(data);
}',
'type'=>'POST'),
array('id'=>'button-b'));
}
public function actiontestAjax2()
{
echo successful;
}
Any help or advice would be appreciated.