This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

JSON tutorial does not work with IE

Forum to discuss ExtJS and other JS plugins

JSON tutorial does not work with IE

by mo_mughrabi » Sat Aug 01, 2009 10:50 am

Hello every one,
I followed the tutorial on how to do json calls from; It works perfectly in FF but with IE I get JS error saying "Object doesn't support this property or method"

Here is what I did

in my indexSuccess.php

Code: Select all
            <?php echo select_tag('districts',options_for_select($districts, 0), array(
               'onChange'    =>  remote_function(array(
                                 'url'      => 'search/ajax?method=getAreasByDistrict',
                                 'with'      => "'DistrictId=' + this.getValue()",
                                 'complete'   => "updateJSON(request)"))
            )) ?>



then i made a JSON.js file and included the file in my view.yml on app level

Code: Select all
function updateJSON(ajax)
  {
    json = ajax.responseJSON;
    var elId;
    for (elId in json)
    {
      Element.update(elId, json[elId]);
    }
}


then, inside the searchActions.php i did the following:

Code: Select all
class searchActions extends sfActions
{
 
 
  public function executeAjax($request) {
     $this->forward404Unless($request->isXmlHttpRequest());
     $this->setTemplate('blank');
     
     $this->getResponse()->setHttpHeader('Content-Type','text/javascript');
     
     return
        $this->renderText(
           call_user_func(array($this, $request->getParameter('method')), $request->getParameter('DistrictId'))
           );
  }

  private function getAreasByDistrict($id) {
     
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('form', 'tag'));
     
     $c = new Criteria();
     
     $c->add(AreaPeer::DISTRICTS_ID, $id);
     
     $objs = AreaPeer::doSelect($c);
     $array=array();
     foreach ($objs as $obj) {
        $array[$obj->getId()]=$obj->getName();
     }
     if (count($objs)==0)
        return json_encode(array('search-area-list-label' => '', 'search-area-list' => ''));
     else
        return json_encode(array('search-area-list-label' => 'Areas', 'search-area-list' => select_tag('area',$array)));
     
     
  }
}


The whole thing works perfectly with FF but when ran with IE it fails with the error i mentioned above.

Can anyone advice on this issue?
mo_mughrabi
Member
 
Posts: 54
Joined: Mon Mar 30, 2009 8:29 pm

Re: JSON tutorial does not work with IE

by mo_mughrabi » Sat Aug 01, 2009 2:33 pm

I made some changes as per the manual in

http://www.symfony-project.org/book/1_0/11-Ajax-Integration


in indexSuccess.php
Code: Select all
            <?php echo select_tag('districts',options_for_select($districts, 0), array(
               'onChange'    =>  remote_function(array(
                                 'url'      => 'search/ajax?method=getAreasByDistrict',
                                 'with'      => "'DistrictId=' + this.getValue()",
                                 'complete'   => "updateJSON(request)"))
            )) ?>



and in action.php
Code: Select all
<?php

class searchActions extends sfActions
{
 
 
  public function executeAjax($request) {
     $this->forward404Unless($request->isXmlHttpRequest());
     $this->setTemplate('blank');
     
     
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     
     $json = call_user_func(array($this, $request->getParameter('method')), $request->getParameter('DistrictId'));
     
     
     return $this->renderText($json);
  }

  private function getAreasByDistrict($id) {
     
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('form', 'tag'));
     
     $c = new Criteria();
     
     $c->add(AreaPeer::DISTRICTS_ID, $id);
     
     $objs = AreaPeer::doSelect($c);
     $array=array();
     foreach ($objs as $obj) {
        $array[$obj->getId()]=$obj->getName();
     }
     if (count($objs)==0)
        return json_encode(array('search-area-list-label' => '', 'search-area-list' => ''));
     else
        return json_encode(array('search-area-list-label' => 'Areas', 'search-area-list' => select_tag('area',$array)));
     
     
  }
}
?>




and my updateJSON script is included in JSON.js

Code: Select all
function updateJSON(ajax)
  {
    json = ajax.responseJSON;
    var elId;
    for (elId in json)
    {
      Element.update(elId, json[elId]);
    }
}


but still not luck, it works perfectly in FF but returns an error with IE

any idea?
mo_mughrabi
Member
 
Posts: 54
Joined: Mon Mar 30, 2009 8:29 pm