Categories > TinyButStrong general >

TBS & AJAX

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: zsom
Date: 2007-09-21
Time: 00:15

TBS & AJAX

Hi,
I'd like to use ajax in my application (more accuratly:http://www.modernmethod.com/sajax/) for something like this:

1, I query the last 5 record from a database.
2, I show it with TBS through a complex table template.
3, My user clicks on the "Show All" button
4, This event calls a JavaScript function
5, the JS function calls a PHP function at the server (in the background)
6, the PHP function gets all records from the db, and creates a response
7, the response will be pushed back to another JS function at the client side (without reloading the page)
8, in the 2. JS function I have to show the data to my user. Usually i write the recieved data into a HTML element's innerHTML.

Sajax provides me the 5., 7. steps in an easy way.
My question:
How can i use my template (which i used at step 2) at step 7?

Is my problem clear for you? Can anyone help me?
Has anyone any experience in TBS & AJAX (i can't find any useful thing here in the forum)?

Thanks:
Zsombor


By: zsom
Date: 2007-09-21
Time: 11:47

Re: TBS & AJAX

I've found a solution!

At step 7, the php function (which will be called, by the JS) is something like this:
...
$TBS2 =& new clsTinyButStrong ;
$TBS2->LoadTemplate('table1.html');
$TBS2->Render = TBS_NOTHING;
$TBS2->MergeBlock('blkData',$data) ;
logSource($TBS2->Source);

return $TBS2->Source;

TBS is really great!
By: zsom
Date: 2007-09-21
Time: 11:48

Re: TBS & AJAX

oops,

logSource(...) is only for debug
By: acon
Date: 2007-09-21
Time: 12:18

Re: TBS & AJAX

oh man... i am having the exact problem. the thing is for sajax is that there is this hybrid php code inside the js. Namely the sajax_show_javascript() function that causes the problem. When I try using TBS for it, it always output the Source code of that function instead of Parse it inside <script type="text/javascript"></script>. I am trying to solve it by either rewriting the Sajax.php (trying to seperate the js and php hybrid code) OR dig into tbs' document and see what i can do about it. I will let you know what i find later. good luck...
By: zsom
Date: 2007-09-21
Time: 13:18

Re: TBS & AJAX

Hi!

I solved this problem in 2 ways:

A,
1. In the main template put this:
<script>
  [var.showAjax;script=[val];subtpl]
</script>

2. in the php file, before merging:
$showAjax = "showAjaxJS.php";

3. the showAjaxJS.php contains only this:
<?php
sajax_show_javascript();
?>

If you inculded the Sajax class at the begining of your main php program, the 3. step will print the neccesary js functions into the generated html code.

B,
If you take a look at the generated html code, which is implemets a working and simple sajax applicaton, you will see, that most of the generetad js are allways the same.
So copy most of them into a simple .js file, include it in the template:
<script src="sajax.js"></script>

For each function, what you export with sajax, you'll need only this js function (put it also into the template):
<script>
function x_getAll() {
sajax_do_call("getAll",x_getAll.arguments);
}
</script>
Where "getAll" is the name of the exported php function. If you have more exported function, call them, like above.

I think solution B, is more effecient, and more clear, and each of your html page, what uses sajax will be smaller.


As i saw, the xajax project is almost the same, so it could be work for that too.

If you still have problems, i can post the full test application.

Bye,
Zsombor