I'm trying to learn AJAX. Can you give me some advises how using AJAX in plugins for piwigo? That is possible? I don't find plugins with ajax, except rv_tscroller, but it don't help me.
Offline
[extension by mistic100] User Collections
[extension by mistic100] Batch Downloader
the core Batch Manager, plugins and themes updater
all my import plugins
all these use AJAX (with or without queue manager)
what do you want to do ?
Offline
mistic100 wrote:
what do you want to do ?
I want get data from database with AJAX.
I have question about {footer_script}. In BatchDownloader you write just
{footer_script require='jquery'}...{/footer_script}
and it is works. But I must write
{footer_script}{literal}...{/literal}{/footer_script}
. Without {literal} SMARTY swear javascript syntax. What I doing wrong?
Offline
Nope you're right. Literal is needed as soon as you write a {
Offline
or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)
Offline
mistic100 wrote:
or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)
Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste
Offline
EvilKant wrote:
I understood! Instead "{" Mistic wrote "{ldelim}". I thought it is variable.
The Smarty documentation is very well; you should take a look
Offline
flop25 wrote:
mistic100 wrote:
or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)
Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste
I agree if you have pure javascript, but sometimes I need smarty variables inside the javascript and I don't want to declare multiple JS variables
Offline
mistic100 wrote:
flop25 wrote:
mistic100 wrote:
or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)
Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste
I agree if you have pure javascript, but sometimes I need smarty variables inside the javascript and I don't want to declare multiple JS variables
Why not /literal var literal? That Washington my point
Offline
this way I don't understand my code afterwards :)
imagine 10 {/literal}{$thats_my_vat}{literal}, I don't like it
Offline
I was turn Evil_Blog to AJAX. But now I have problem with support of Extended Description: I can't get ExDesc functions from separate php script. Do you have ideas?
Beta-version you can get here http://picmun.ru/Evil_Blog.zip
and codes:
separate php script which geting posts from database:
<?php define('PHPWG_ROOT_PATH', '../../'); include(PHPWG_ROOT_PATH.'include/common.inc.php'); if (isset($_POST['number'])) { $query = "SELECT id, UNIX_TIMESTAMP(date) AS date, header, text FROM `".Evil_Blog_Table."` WHERE 1 ORDER BY `date` DESC LIMIT ".$_POST['number'].", 1"; $result = pwg_query($query); $row = pwg_db_fetch_assoc($result); //более вменяемая обработка результата из базы, нужно для нормальной работы SMARTY if (isset($_POST['date_format'])){ $row['date'] = date($_POST['date_format'], $row['date']); } $ExDesc = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); if($ExDesc['state'] == 'active') { $row['text'] = get_extended_desc($row['text']); $row['header'] = get_user_language_desc($row['header']); } $rez= $row['id'].'|'.$row['date'].'|'.$row['header'].'|'.$row['text']; echo $rez; } ?>
and AJAX code in .tpl-file:
{footer_script require='jquery'} function ajax_load_post(n){ldelim} $.ajax({ldelim} url: "plugins/Evil_Blog/ajax_load_posts.php", type: "POST", data: {ldelim} "number": n, "date_format": "{$date_format}"}, async: false, success: function(data){ldelim} var posts = data.split('|'); var header = '<span class="post_title">'+ {if isset($show_number) and $show_number} '<span class="post_number">'+posts[0]+'</span> * '+ {/if} '<span class="post_header"><a href="{$ROOT_URL}?/blog/id/'+posts[0]+'">'+posts[2]+'</a></span>'+ {if isset($show_date) and $show_date} '<span class="post_date">'+posts[1]+'</span>'+ {/if} '</span>'; $('<li class="thumbnailCategory" id="post_'+n+'"></li>') .hide() .append(header) .append('<div class="post_description">'+posts[3]+'</div>') .appendTo('.evil_blog_posts') .fadeIn(500); } }); }; $(document).ready(function() {ldelim} for (var i = 0; i <= {$post_per_page-1}; i++) {ldelim} ajax_load_post({$number}+i); } }); {/footer_script}
Offline