javascriptajaxpresenternettelatte

Javascript, Ajax, latte and Presenter problem. Can't use GET request on file in another directory


I have a question. I was tasked to add some function to our web application. It is build on php presenter by somebody else so it's quite difficult for me to debug as I never work with this stuff.

I am trying to add that feature without creating another presenter, classes etc. I know that, it is not ideal.

So I have this problem. I am including .latte file (php), which is located in:

root/app/presenters/templates/obligation/function.latte

<!-- The Modal -->
<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">

        <span class="close">&times;</span>
        
        {include 'data.latte'}

        <div id="firma_pass"></div>

        
    
    </div>
</div>

and than AJAX in .javascript file, that I want to be called on data.latte in:

root/web/js/handler.js

var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', "data.latte?toSearch=" + something, true);
    xmlhttp.send();

But I can't get it to work. I can't use GET request on .latte file located in templates or import .latte file from web directory. Moving .js to templates is also no good.

So I want to ask, is it even possible to do something like this, or I need to implement it by another way.

Thanks for answers.


Solution

  • Okay, I found the answer. Problem wasn't in the path, but in the definition of file. When latte file is called, it is done so without the suffix. So all I needed to do was:

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', "data?toSearch=" + something, true);
    xmlhttp.send();