XF 2.0 Run of JavaScript code after ajax call of a template that includes it

Scandal

Well-known member
Hello all! :)

I have this issue in XF2:
Well, I'm making a jQuery.ajax({}) call on a page which returns a template via the pub controller:
PHP:
$this->setResponseType('json');
return $this->view('', 'my_template');

The response code on jQuery.ajax({}) is set to json too, so NOT all the page container of XF will returned.
And gives the content to a div via the success function (response = the response) :
JavaScript:
$('#ajax_container').html(response.html.content);

The issue is that "my_template" template includes (beydon the basic HTML I need), and some javascript code which I need to run immediately after the ajax load. I mean that some javascript will applied to #ajax_container that I need to run.
The strange issue is that I have use by the same way it on a different platform (vBulletin 4) with no issues.

That ajax loaded javascript includes:
- a jQuery(document).ready(function(){
- some fadeIn(), hide() and show() for specific elements
- and some other functions whose includes also other jQuery.ajax({}) calls.
If it was a main page and not a page that loaded via ajax it should work fine.

Is there any special control by XF2 on the ajax requests in connection with run of javascript via their response?

To conclude, I have try to use inside "my_template", both <script></script> and <xf:js></xf:js> tags but with no improvement.

Any idea?
Thanks :)
 
Found the solution ;)

It has something to do with the json setting of jQuery.ajax({}). I changed it to "html" and parse it via jQuery json string parser before apply it with .html() and all ok.
 
Back
Top Bottom