ako vratit json data? cez ajax?
- maria288
- Člen | 38
<script>
onLazyRead: function(node) {
node.appendAjax({
url: {link combo!},
dataType : 'json',
data: { id: node.data.key},
success: function(res){
alert(res);
},
error: function(res){
//dojde len sem ! cize nieco je zle
alert(res);
}
});
}
</script>
<?php
public function handleCombo($id)
{
if (!$this->presenter->isAjax()) {
//najprv jednoduchsie cisty text v tvare json dat, ani to len nevrati
$this->sendResponse("[ {'title': 'SubItem 1', 'isLazy': true,'key': '1' }]");
}
}
?>
kto s tym vie pomoct ?
- voda
- Člen | 561
musíš použít JsonResponse
$this->sendResponse(new JsonResponse(array(
'title' => 'Subitem 1',
...
)));
- maria288
- Člen | 38
<?php
public function handleCombo($id)
{
$this->sendResponse(new JsonResponse(array(
'title' => 'Subitem 1',
'key' => '1'
)));
}
?>
hlavicka>
Request URL:http://www.realvea.sk/?…
Request Method:GET
Status Code:500 Internal Server Error
Request Headers
Accept:application/json, text/javascript, /; q=0.01
Accept-Charset:windows-1250,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:sk-SK,sk;q=0.8,cs;q=0.6,en-US;q=0.4,en;q=0.2
Connection:keep-alive
Cookie:__utmz=1.1308310033.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
PHPSESSID=d39339124222f1e6c557dc4901d9f19f; nette-browser=wr628u6dsx;
__utma=1.1172058640.1308310033.1308310033.1308566278.2; __utmc=1;
__utmb=1.5.10.1308566278
Host:www.realvea.sk
Referer:http://www.realvea.sk/
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.24 (KHTML, like Gecko)
Chrome/11.0.696.68 Safari/534.24
X-Requested-With:XMLHttpRequest
Query String Parameters
do:combo
_:1308567918321
id:5
Response Headers
Cache-Control:max-age=0
Connection:close
Content-Encoding:gzip
Content-Length:26
Content-Type:text/html; charset=UTF-8
Date:Mon, 20 Jun 2011 11:05:27 GMT
ETag:„x46a4d6asdwe“
Expires:Mon, 20 Jun 2011 11:05:27 GMT
Last-Modified:Mon, 20 Jun 2011 11:05:27 GMT
Pragma:no-cache
no-cache
Server:Apache
Set-Cookie:PHPSESSID=d39339124222f1e6c557dc4901d9f19f; path=/; httponly
nette-browser=wr628u6dsx; path=/; httponly
Vary:Accept-Encoding
X-Powered-By:Nette Framework
- newPOPE
- Člen | 648
Je to kvoli cache requestov,kedze sa to cislo meni tak browser to berie ako ‚novy‘ request cize ho aj realne posle, tusim ze IE to bez cisla proste chytil a nic neposlal (v davnejsich dobach, neviem ako tie novsie verzie…)
@maria288 – pozeram ze uz tu mas 2he vlakno ohladom toho isteho cize AJAXu. dporucujem najskor nastudovat co a ako funguje, nasledne ti zacnu veci do seba zapadat ;-)