| JSON - multiple ajax calls - revisited [message #8109] |
Thu, 29 June 2006 04:00  |
replicah Messages: 43 Registered: June 2006 |
Member |
|
|
with JSON, what if i want to populate multiple divs with other php pages rather than just a string? as in the normal link_to_remote..
any ideas?
thanks!
|
|
|
|
|
|
| Re: JSON - multiple ajax calls - revisited [message #8178 is a reply to message #8155 ] |
Fri, 30 June 2006 11:59   |
noel Messages: 62 Registered: January 2006 Location: france, 94 |
Member |
|
|
Hi,
Try that:
public function executeTest(){
$firstDiv = $this->getPresentationFor('module', 'action');
$secondDiv = $this->getPresentationFor('module', 'other_action');
$output = sprintf('[["firstDiv","%s"],["secondDiv","%s"]', $firstDiv, $secondDiv);
$this->getResponse()->setHttpHeader("X-JSON", '('.$output.')');
return sfView::HEADER_ONLY;
}
hope this helps
noel
|
|
|
|
| Re: JSON - multiple ajax calls - revisited [message #8275 is a reply to message #8179 ] |
Tue, 04 July 2006 04:36   |
replicah Messages: 43 Registered: June 2006 |
Member |
|
|
thanks for your response noel!
the getPresentationFor will do the trick..
however, i still can't get it going..
this is what i have currently:
public function executeRefresh()
{
$firstDiv = $this->getPresentationFor('events', 'racinghome');
$secondDiv = $this->getPresentationFor('leftnav', 'racingcompetition');
$output = sprintf('[["content1","%s"],["content2","%s"]]', $firstDiv, $secondDiv);
$this->getResponse()->setHttpHeader("X-JSON", '('.$output.')');
return sfView::HEADER_ONLY;
}
and in the view:
<?php echo use_helper('Javascript'); ?>
<div id="content1">
content 1
</div>
<div id="content2">
content 2
</div>
<?php echo link_to_remote("refresh", array("url" => "/leftnav/refresh", 'complete'=>'updateJSON(request,json)') ); ?>
can you see any real flaws here??
and one more thing 
even the most basic example on http://www.symfony-project.com/trac/wiki/AjaxAndJSON doesn't work in IE or Safari... what the??
thanks for any help!!!!!
[Updated on: Tue, 04 July 2006 04:37]
|
|
|
|
|
| Re: JSON - multiple ajax calls - revisited [message #8725 is a reply to message #8690 ] |
Wed, 12 July 2006 15:41   |
noel Messages: 62 Registered: January 2006 Location: france, 94 |
Member |
|
|
Hi,
Try that:
action.class.php
public function executeUpdateDivs(){
$this->firstDiv = $this->getPresentationFor('beta', 'firstDiv');
$this->secondDiv = $this->getPresentationFor('beta', 'secondDiv');
$json = new Services_JSON();
$output = $json->encode($this->getVarHolder()->getAll());
$this->getResponse()->setHttpHeader("X-JSON", '('.$output.')');
return sfView::HEADER_ONLY;
}
public function executeIndex(){}
public function executeFirstDiv(){}
public function executeSecondDiv(){}
indexSuccess.php
<?php use_helper('Javascript'); ?>
<script language="JavaScript" type="text/javascript">
function updateJson(request, json){
for (var prop in json){
Element.update(prop, json[prop]);
}
}
</script>
<?php echo link_to_remote('update', array('url' => 'beta/updateDivs', 'complete' => 'updateJson(request, json)')); ?>
<div id="firstDiv">not updated</div>
<div id="secondDiv">not updated</div>
Next, put some text in firstDivSuccess.php and secondDivSuccess.php, don't forget to create updateDivsHeaders.php and it works.
noel
|
|
|
|
|
|
|