Ajax And Ie9

I’m new to Yii. So I have 3 questions:

First:

The following ajax call works well in FF and Chrome but not in IE9. Any idea why?




function mudouservico(){


$.ajax({

      type: "POST",

      url:    "<? echo Yii::app()->createUrl('faturas/DS'); ?>",

      data:  {serv:codservico.value},

      success: function(data){          

          var jsonOb = eval('(' + data + ')');

          servico.value=jsonOb.designacao;

          preco.value=parseFloat(jsonOb.preco).toFixed(2).toString();

          recalcula();

      },

      error: function(xhr){

           alert("Erro na chamada ao servidor ("+xhr.readyState+")"+this.url);

      }

    });

}



Second:

What’s the difference between writing javascript code inside a view file using the traditional way…




<script type="text/javascript"> 

....

</script>




… or registering the script?

Third:

What’s the best yii approach to make calculations between elements on a view? Let’s say changing a Total when Price or quantity changes?

Thank you for your patient and attention to the newbie…

  1. try protected/views/layouts/main.php, the following code helps me workout in ie8

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  1. no difference, think about using native php vs yii, try to use yii-way as much as possible;

  2. is this simple js trick?

[size=2]2. – if you register the script:[/size]

  • [size="2"]you may render it in more convenient place, providing third argument $position[/size]
  • [size="2"]you may omit typing jquery onready/onload statement using the same argument $position[/size]
  • [size="2"]you may use heredoc syntax[/size]

These differences are minor on the first look, but may simplify your dev-life.

  1. – just write javascript code, there’s nothing yii-specific.

Thanks rootbear…

That particular line of code was already there by default… That’s not it… :(

Also thanking yugene for the explanations.