Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty & Ajax

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian
View previous topic :: View next topic  
Author Message
mellowonpsx
Smarty Rookie


Joined: 03 Jan 2008
Posts: 5

PostPosted: Fri Jan 04, 2008 11:34 am    Post subject: Smarty & Ajax Reply with quote

Stavo iniziando a lavorare con ajax e smarty. Siccome xajax funziona bene (di solito) ho pensato di integrare le due classi.

Il codice prodotto è questo:

index.php
Code:
<?php

include_once("common_smarty.php");
include_once("common_xajax.php");

//--xajax--//
$xajax  =  inizializzaXajax();

$xajax->registerFunction("myFunction");

$xajax->processRequest();

//--smarty--//
$smarty = inizializzaSmarty();

$smarty->assign("title","Benvenuto");

$smarty->assign("xajax_javascript",$xajax->getJavascript("xajax/"));

$smarty->display("index.tpl");

?>


common_ajax.php
Code:

<?php

include_once("config.php");
include_once("auth.lib.php");
include_once("common_page.inc.php");
include_once("common_db.inc.php");

define("XAJAX_DIR", "./xajax/");
require(XAJAX_DIR."xajax.inc.php");

function inizializzaXajax()
{
 $xajax = new xajax();
 
 $xajax->debugOn();
 $xajax->statusMessagesOn();

 return $xajax;
}

function myFunction($arg)
{
 $newContent = "Value of \$arg: ".$arg;

 $objResponse = new xajaxResponse();

 $objResponse->assign("SomeElementId","innerHTML", $newContent);

 return $objResponse;
}

?>


common_smarty.php
Code:
<?php

include_once("config.php");
include_once("auth.lib.php");
include_once("common_page.inc.php");
include_once("common_db.inc.php");

define("SMARTY_DIR", "./Smarty/Libs/");
require(SMARTY_DIR."Smarty.class.php");

function inizializzaSmarty()
{
 $smarty = new Smarty();

 $smarty->template_dir = "templates/";
 $smarty->compile_dir = "templates_c/";
 $smarty->config_dir = "configs/";
 $smarty->cache_dir = "cache/";
 
  return $smarty;
}
?>


index.tlp
Code:
{* Smarty *}
{include file="header.tpl" title="Homepage"}
<div id="SomeElementId">
</div>
<div id="Button">
 <button onclick="xajax_myFunction('It worked!');"> Clicca </button>
</div>
{include file="footer.tpl"}


header.tlp
Code:

{* Smarty Header *}
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
 <head>
  <title>AX.SY - AjaX SmartY (mellowonpsx project) / page {$title|nl2br} </title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/stilebase_ie.css" />
  <!--[if !IE]><!-->
   <link rel="stylesheet" type="text/css" href="css/stilebase.css" />
  <!--<![endif]-->
  {$xajax_javascript}
 </head>
 <body>
  <div id="testa">
   <p class="testo">
    {$title|nl2br}
   </p>
  </div>
{* End of Smarty Header *}


Il footer non ha importanza perchè non fa nulla.

Il problema è che quando schiaccio il bottone viene fuori un errore:
Code:
Received: <br /> <b>Notice</b>: Undefined variable: sResponse in <b>c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php</b> on line <b>747</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php:747) in <b>c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php</b> on line <b>763</b><br /> <?xml version="1.0" encoding="utf-8" ?><xjx><cmd n="as" t="SomeElementId" p="innerHTML">Value of $arg: It worked!</cmd></xjx>


Any idea?
Back to top
View user's profile Send private message
flatfield
Smarty Rookie


Joined: 30 Apr 2007
Posts: 18
Location: Genova (Italy)

PostPosted: Fri May 23, 2008 4:04 pm    Post subject: Reply with quote

Generalmente l'errore

"Cannot modify header information"

compare quando si è già scritto del codice "a video", cioè HTML o con "print" PHP e si tenta di eseguire un comando PHP di questo tipo

header("location:index.php");

Tale comando, o altri che modificano l'header, devono comparire prima di qualsiasi output
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP