View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 13, 2006 11:25 pm Post subject: SmartJax 1.0 |
|
|
I have released an AJAX library for PHP aptly named SmartJax, soon to have drop-in ready Smarty plugins once I feel the codebase is stable.
The core SmartJax library has no dependency on Smarty, but can easily be integrated into templates. Smarty plugins will help make common uses a snap (vote counting, username lookups, etc.)
SmartJax is loosely based off the My-BIC library by Jim Plush. SmartJax pays close attention to accessability, so when properly programmed your applications will continue to function without xmlhttprequest, or even javascript in many cases.
Please help test, thanks!
http://www.phpinsider.com/php/code/SmartJax/ |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Sun Apr 02, 2006 3:55 am Post subject: |
|
|
GJ, has usual
I've been working in some plugins but theres a problem.
Is it possible to call more then 1 function at a time ?
I've made a simple event calendar (Blog like) and loads with smartjax all good but i wanted to call a second function to load the events for the day, all onload. And the problem is that it will only load the last function.
Can you help me out ?? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Apr 02, 2006 5:44 pm Post subject: |
|
|
I haven't tested it, but something like this:
Code: | function smartjax_hello() {
return sjObj.call("helloworld1", cbHello1) && sjObj.call("helloworld2", cbHello2);
} |
That should execute both ajax functions and return true if they both were successful. |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Mon Apr 03, 2006 12:16 am Post subject: |
|
|
It seems to overwrite the first callback with the second.
The problem is in the response if i use
Code: |
self.setTimeout('sjObj.call("helloworld2", cbHello2);',1000);
|
it will work.
I allso find out that this problem is "normal" because im trying to use concurrent requests and the timeout gives enough time to the first callback to finish.
https://blueprints.dev.java.net/ajax-faq.html#concurrent_requests |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 03, 2006 12:54 am Post subject: |
|
|
just and idea, did you try:
Code: | sjObj.async = false; |
that should force the connection to be synchronous, and wait for the response. |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Mon Apr 03, 2006 4:23 am Post subject: |
|
|
Nope doesnt solve it. BUT because of that i think i found the problem.
Code: |
function SMARTJAX(server_url)
this.callBackFunc = "";
|
this is set when creating the object and assumes later on the name the callback function.
Code: |
SMARTJAX.prototype.call
this.callBackFunc = userCallBackFunc;
|
Because i call it almost the same time, its loses the callback before request returns to the callback.
I tryed to create a new object every time i call the function but doest responds.
Ill try to make some more tweaks ... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 03, 2006 4:48 am Post subject: |
|
|
Did you try creating two separate SmartJax objects, one for each call? |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Mon Apr 03, 2006 5:21 am Post subject: |
|
|
mohrt wrote: | Did you try creating two separate SmartJax objects, one for each call? |
Now im realy mess up
I dont think you can because of the responseHandler it uses the sjObj.
Maybe the my problem its because the responseHandler uses only 1 object and makes it respond only to the last request. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 03, 2006 1:24 pm Post subject: |
|
|
Something like this:
Code: |
var sjObj = new SMARTJAX("/smartjax/smartjax_server.php");
var sjObj2 = new SMARTJAX("/smartjax/smartjax_server.php");
function smartjax_hello() {
return sjObj.call("helloworld1", cbHello1);
}
function smartjax_hello2() {
return sjObj2.call("helloworld2", cbHello2);
}
<a href="" onclick="return(smartjax_hello1() && smartjax_hello2());">click</a>
|
|
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Mon Apr 03, 2006 3:02 pm Post subject: |
|
|
i've tryed that but it doenst work because of the response Handler only uses one object sjObj.
Code: |
SMARTJAX.prototype.responseHandler = function()
{
// 4 == "complete"
if (sjObj.req.readyState == 4) {
...
|
sjObj Is the only object that can respond leaving sjObj2 without a response handler. |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Mon Apr 03, 2006 3:12 pm Post subject: |
|
|
I just took a look around my-bic source and found this
Code: | /**
* This method will allow you to create a "command queue" so ajax requests are sent in order they were fired.
* You will be able to keep your request/responses in order they were sent
*/
XMLHTTP.prototype.add2Queue = function(queryVars, userCallback)
{
var addAjax = new Array();
addAjax['queryVars'] = queryVars;
addAjax['userCallback'] = userCallback;
this.queue.push(addAjax);
} |
It doenst seems you are using this queue. Maybe its a new addition. |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Tue Apr 04, 2006 3:49 pm Post subject: |
|
|
Hi Monte,
example Code from README has a Bug in it:
Code: |
You will see a basic javascript setup similar to this:
<html>
<head>
<script type="text/javascript" src="/smartjax/smartjax.js"></script>
<script type="text/javascript">
var sjObj = new SMARTJAX("/smartjax/smartjax_server.php");
function smartjax_hello() {
return sjObj.call("helloworld", cbHello);
}
function cbHello(resp) {
document.getElementById('content').innerHTML = resp;
}
</script>
</head>
<body>
<a href="" onclick="return(!smartjax_hello());">click me!</a>
<div id="mystuff"></div>
</body>
</html> |
Code: | <div id="mystuff"></div>
|
has to be
Code: | <div id="content"></div>
|
Bye,
Markus |
|
Back to top |
|
migas Smarty Regular
Joined: 07 Apr 2004 Posts: 73 Location: Porto, Portugal
|
Posted: Tue Apr 04, 2006 6:15 pm Post subject: |
|
|
Just to explain how i am using the smartjax with Smarty and why am i having all these problems.
The background :
I really love how smarty divides all the code in 2 layers (code / template) and because of that i really have difficulties when i only use php.
So i tried to create a structure that can use Ajax with smarty.
Problem :
Why am i only using Ajax for outputting a simple string/array with only a few values?
Why can i output all the data even with HTML?
One of the possible solutions:
Javascript
Code: |
//Using JSON
function smartjax_template(tpl,div,form) {
url = "&tpl=" + tpl;
if(div) {smartjax_loading(div); url = url + "&div=" + div ;}
if(form) sjObj.getForm(form);
return sjObj.call("template" + url , cbtemplate);
return true;
}
function cbtemplate(resp) {
document.getElementById(resp.div).innerHTML = resp.output;
}
function smartjax_loading(div){
document.getElementById(div).innerHTML = "<div style='width: 100%; text-align:center;padding:2px 2px 2px 2px;'><img src='smartjax/indicator.white.gif' /></div>"
}
|
Plugin
[php:1:0e035592b9]
<?php
/*
* Create this 2 folders.
* <...>php/
* <...>templates/
*
* Then you create 2 files
* <...>php/demo.php - Here you drop all the need "assign" for the tpl (its optional)
* <...>templates/demo.tpl - Here you drop all smarty/html code
*
* This PATH_fs will be the default path structure
*/
define("PATH_fs","/MyDocumentRoot/");
class template
{
var $request;
function template($request_string)
{
$this->request = $request_string;
}
/**
* method to return the contents of xmlhttprequest action
*
* @return mixed
* depending on the format chosen in smartjax:
* TEXT => return a string of text
* XML => return a valid XML document
* JSON (default) => return a string of text OR PHP associative array
*/
function return_response()
{
$resp_["tpl"] = $Pag = $this->request["tpl"];
// In case you dont especify the div id it uses as tpl name as a div id
$resp_["div"] = ($this->request["div"]?$this->request["div"]:$this->request["tpl"]);
if($Pag)
{
if(is_file(PATH_fs."php/".$Pag.".php")) include PATH_fs."php/".$Pag.".php";
if(is_file(PATH_fs."templates/".$Pag.".tpl")) $resp_["output"] = $smarty->fetch($Pag.".tpl");
else $resp_["output"] = "No template Found !!!!";
}
return $resp_;
}
/**
* method to test if xmlhttprequest is authorized
*
* @return boolean true/false
*/
function is_authorized()
{
return true;
}
}
?>
[/php:1:0e035592b9]
This works fine, but because when you make more than 1 consecutive call theres no queue to make the second call wait for the first to finish, you are limited to make only 1 call per event. |
|
Back to top |
|
fastwings Smarty n00b
Joined: 17 Apr 2006 Posts: 2
|
Posted: Tue Apr 18, 2006 7:24 am Post subject: i think |
|
|
that u need add more power to the php here in the plugin cuz its limit to javascript and u cant add staff that make the plugin with real power like i need do in ajax staff the call to db and real filesystem u know how nightmare its add in javascript code so me idea give power easy use to the code of php and not javascript |
|
Back to top |
|
TC! Smarty n00b
Joined: 21 May 2006 Posts: 2
|
Posted: Sun May 21, 2006 1:40 pm Post subject: |
|
|
I thought I'd post here that if you follow the link for this it tells you that this is no longer being developed. |
|
Back to top |
|
|