Understand how to use AJAX to work with smarty in php

What I'm trying to do is probably very simple (the irony is that I'm stuck).

I have a file that smarty divides into a (template and php) file. I have a small js script that sends an ajax request to update a variable in a file (php).

In the php file based on what I get from AJAX, I do

$smarty->assign('test',$_GET['test'])

and then

$smarty->display('index.tpl')

Now, since this is AJAX, I am confused by what to send as an answer, since I am already showing the template.

+3
source share
2 answers

It all depends on what your application will do with the response to the AJAX request.

( javacsript land) - ( JSON ), html (DOM) .

, AJAX html. , html.

0

Smarty, , Ajax Smarty - , ? https://stackoverflow.com/questions/630714/smarty-the-best-choice/632458#632458

, $smarty->display() echo $smarty->fetch()

if($request->isXmlHttpRequest()) {
    echo $smarty->fetch('your-file.tpl');
}
0

Source: https://habr.com/ru/post/1780558/


All Articles