0

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.

  • I have no idea what you are trying to achieve or what specifically you have issue with. Why are you including `data.latte` from `data.latte`? For the AJAX request, the URL should match your routes (if you use simple `//` route it might be `/obligation/data`). – Jan Tojnar Aug 27 '21 at 00:36
  • @JanTojnar sorry, that was typo with data.latte. It is not obligation/data. Problem is that ajax starts it's route from web, obligation and web are on same level so ajax cant access /obligation/data normally and I don't know, how to make that route another way. – DatZiggyZig Aug 27 '21 at 07:04

1 Answers1

0

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();
Dharman
  • 30,962
  • 25
  • 85
  • 135