response type (adding "json" as the 4th parameter in the $.post() call)?
BEREGU wrote:
>
> Hello,
>
> I wanted to print json formatted response, which is passed from
> controller passing to a view script.
> The response, which is catched with firebug is:
>
> |{"ai80":"1050","ai92":"1100","diesel":"1300"}|
>
>
> But I can't see any of those values on my browser. Please advice me what
> I made wrong.
>
>
>
> In the controller:
> =============
> $fuels = new BEREGU_FuelsDbTable();
> $result = $fuels->fetchAll();
>
> foreach ($result as $fuel){
> switch ($fuel->id) {
> case '2':
> $ai80 = $fuel->price;
> break;
>
> case '3':
> $ai92 = $fuel->price;
> break;
>
> case '6':
> $diesel = $fuel->price;
> break;
> }
> }
>
> $item = array();
> $item['ai80'] = $ai80;
> $item['ai92'] = $ai92;
> $item['diesel'] = $diesel;
>
> echo Zend_Json_Encoder::encode($item);
> ///////////////////////////////
>
> In the view script
> =============
> function getPriceJson(volume)
> {
> $.post(
> "/async/getprice",
> {
> "volume" : volume
> },
>
> function(response)
> {
> $("#ai92").append(" # "+response.diesel+" ");
> $("#ai80").append(response.ai80);
> $("#diesel").append(response.diesel);
> });
> }
> //////////////////////////////////////
>
>
>
>
> Sincerely,
> Enkhbilguun Erdenetsogt
>
> begin:vcard
> fn:Enkhbilguun Erdenetsogt
> n:Erdenetsogt;Enkhbilguun
> email;internet:enkhbilguun@beregu.com
> tel;cell:99113638
> x-mozilla-html:TRUE
> version:2.1
> end:vcard
>
>
>
--
View this message in context: http://old.nabble.com/How-can-I-to-print-Json-formated-response--tp26111958p26139117.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论