views:

90

answers:

1

Hi,

I didn't write the following code and I am not a Javascript expert. So please excuse me if it seems to you a trivial bug. However here is the code:

jQuery.ajax({
    type: barobj.method,
    url: handler,
    beforeSend: function (request) {
     request.vote_id = vid;
            ...
    },
    complete: function (request, textStatus){
           jQuery('#actor').filter("[title='"+request.vote_id+"']")
           ...
    },

It is running fine in FF, Chrome, Safari but not (surprise?) in IE7 & IE8.

The exception is Error: Object doesn't support this property or method at line request.voteid = vid After some debugging, I found out that in FF, request has type XMLHttpRequest whereas in IE 7 & 8, it has type IXMMHttpRequest

So what are the reasons of the exception? And how can I solve it in a way that I can get back the vote_id value in the onComplete event?

Thank you very much,

Fabien.

+2  A: 

Javascript supports closures, so your complete function should be able to access any variables in scope for the calling code. You don't need to explicitly preserve and pass the vid value to it.

jQuery.ajax({
   type: barobj.method,
   url: handler,
   beforeSend: function (request) { },
   complete: function (request, textStatus){
          jQuery('#actor').filter("[title='"+ vid +"']")
          ...
   },
richardtallent
Thank you. It works. But do you know why there is an exception in IE and not in FF ?
fabien7474
JQuery chose to continue using IE's ActiveX object, IXMLHttpRequest, rather than the native XMLHttpRequest support added in IE7 (the code comments suggest the IE7 implementation has issues--see v1.3.2, line 3378). Native browser objects like XMLHttpRequest support JavaScript "expando" properties, but ActiveX objects do not.In any case, IE6 (curses be on it) doesn't have native XMLHttpRequest support, so you're better off not assigning expando properties to the Request object anyway, just in case you still have any IE6 users out there.
richardtallent
Thx a lot! It is more clear for me now.
fabien7474
@richardtallent: That probably should be an answer. I was about to write something very similar.
Tim Down