IE8 ajax response problem (solved)

Hi, I have a function that checks the readyState from the server’s response after an ajax call.

The function works fine in FF but not in IE8. I added a few “alerts” to try to debug:

function handleAjaxServerResponse(e){

‘use strict’;

try {

alert(e); // produces “[object Event]” in FF, but "undefined" in IE8

if (typeof e == ‘undefined’) e = window.event;

alert(e); // produces “[object Event]” in FF, but "[object]" in IE8

var ajax = e.target || e.srcElement;

alert(ajax); // produces “[object XMLHttpRequest]” in FF, but "null" in IE8

Obviously, from here on, the rest of the function does not work in IE8.

I use this code to create the request:

if (window.XMLHttpRequest) {

ajax = new XMLHttpRequest();

}

else if (window.ActiveXObject) {

ajax = new ActiveXObject(‘MSXML2.XMLHTTP.3.0’);

}

return ajax;

Any ideas?

Thanx

Why don’t you use JQuery’s $.ajax() method? It takes care of browser inconsistencies and it is already bundled with yii.

After more conversation with Haensel he said:

"You can use CHtml::ajax in your view. It is PHP code and can not be stored in a separate javascript file.

If you want to store your function in a separate javascript file, then use JQuery.ajax (also called $.ajax).

Both CHtml::ajax and JQuery.ajax will take care of browser inconsistencies and will also help you with all the “readyState” and ActiveXObject (pure ajax) stuff. You don’t have to worry about such things anymore, just focus on the interesting parts."

Personally, I prefer putting my functions in separate javascript files, because it allows you to re-use your code. Haensel also mentioned that it makes debugging easier.

Thanks for summing things up :)

The $.ajax function works fine.

Get some samples here: http://api.jquery.com/jQuery.ajax/

For those interested, there is a working example here:

http://www.yiiframework.com/wiki/323/dynamic-parent-and-child-cgridciew-on-single-view-using-ajax-to-update-child-gridview-via-controller-with-many_many-relation-after-row-in-parent-gridview-was-clicked/