I’m having some trouble getting ajax links to work when they’re created as a result of an earlier Ajax query. I have a page which generates a bunch of content when a link is clicked. The content depends on which link is clicked, but it always contains an Ajax link. I’m trying to get a second Ajax call to simply return some plain text and put this text into an empty div. The code snippets below relate to the second Ajax link
The div to update:
<div id="dialogWrapper"></div>
The action (in my controller) called by my Ajax link:
public function actionAjax(){
echo "test string";
}
The ajax link:
CHtml::ajaxLink('clickMe', array('controller/ajax'), array('update'=>'#dialogWrapper')
Now, if I place that Ajax link in the main view file for my page, then it works fine - clicking the link populates the div with the string ‘test string’.
Next, if I leave that first link in the main view file, and put a copy of it inside a separate view file, which gets partially rendered by an earlier Ajax query, then both links will do the same thing, as expected.
Next, I tried changing the second link to run a different action:
CHtml::ajaxLink('clickMe', array('controller/anotherAjax'), array('update'=>'#dialogWrapper'));
This is where things get wierd because the link which should now point to the action ‘anotherAjax’ still in fact runs the exact same query as before - i.e. both links still update the div with the result of a query to the action ‘ajax’.
Finally, I tried removing the ajax link from my main view file, so we are left with only the one in the partial view file. In this case, the link does nothing whatsoever. Is there something wierd about the way things are generated by partial view, or when content is produced via an Ajax request, that means I can’t have another Ajax request defined in this way?
(Sorry if thats a confusing description - I’m really struggling to make it any clearer)