Hi Folks, I have a Django application with a scratch-built AJAX Javascript layer that works well on Safari and Firefox, but not on IE. I am attempting to rewrite it using MochiKit, but am having some issues with the doXHR function, in that I seem to be getting back an empty XHR from my Django Python script. I have a few questions:
1) Can anyone see what I'm doing wrong in the MochKit code? As I said, I get back an empty XHR. Am I accessing the return XHR incorrectly (should be the "result" argument in my callback, right?) When I use typeof(result) I get the expected XHR type. result.toJSONString() yields {}. 2) In the first code sample, I am able to access ajaxRequest.response_text, which should be the same as resulot.response_text in the MochiKit example, but the result appears to be empty. Do I need to do something different to access the fields of the doXHR result argument? 3) Am I getting back an empty result because doXHR sets some default headers for the request that are incompatible with the Django return type? What would be a good set of headers to use? The generic code that works looks like: selectEntity : function (entity) { try { var url = '/visionary/game/select/?xhr'; var eId = 'harp_game_id'; var getData = eId + '=' + escape(entity.pk); var ajaxRequest = this.createRequest(); // Creates a generic, platform appropriate XHR ajaxRequest.open("POST", url, true); ajaxRequest.onreadystatechange = MochiKit.Base.bind(function () { try { if(ajaxRequest.readyState == 4) { if(ajaxRequest.status == 200) { var response = eval( "(" + ajaxRequest.responseText + ")"); if (response.success) { var consoleMessage = response.initial_console_message; MochiKit.Base.map(MochiKit.Base.bind(function (index) { consoleMessage += "<br> " + index + ": " + response[index]; var rowId = [this.app, this.cn, response[index], 'row'].join('_'); this.setRowHighlight(MochiKit.DOM.getElement(rowId), index == 'newId' ? true : false); }, this), ['newId', 'oldId']); this.updateConsole(consoleMessage); } else { this.errorsToConsole(response); } return true; } } } catch(e) { MochiKit.Logging.logError('selectEntity Callback fn ' + e); } return false; }, this); ajaxRequest.setRequestHeader("Content-Type", "application/ x-www-form-urlencoded"); ajaxRequest.send(getData); return true; } catch(e) { MochiKit.Logging.logError('selectEntity(' + entity + ') ' + e); } return false; } The MochiKit heavy code I can't get a response from looks like: selectEntity : function (entity) { try { var url = '/visionary/game/select/?xhr'; var q = 'harp_game_id=' + entity.pk; var r = {method: 'POST', mimeType: 'application/javascript', headers: [['Content-Type', 'application/x-www- form-urlencoded'], ['Accept', 'application/ json']], sendContent: q}; var d = MochiKit.Async.doXHR(url, r); d.addCallback(MochiKit.Base.bind(function (result) { try { MochiKit.Logging.log('Callback Request: ' + result); var response = eval( "(" + result.response_text + ")"); if(typeof(response) != 'undefined') { var consoleMessage = response.initial_console_message; MochiKit.Base.map(MochiKit.Base.bind(function (index) { consoleMessage += "<br> " + index + ": " + response[index]; var rowId = [this.app, this.cn, response[index], 'row'].join('_'); this.setRowHighlight(MochiKit.DOM.getElement(rowId), index == 'newId' ? true : false); }, this), ['newId', 'oldId']); this.updateConsole(consoleMessage); } else { throw new Error('Failed to resolve XHR Response. Result: ' + [typeof(result), result, result.toJSONString()].join(', ')); } } catch(e) { MochiKit.Logging.logError('selectEntity Callback fn ' + e); } }, this)); d.addErrback(MochiKit.Base.bind(function (result) { MochiKit.Logging.log('Callback Request: ' + result); }, this)); } catch(e) { MochiKit.Logging.logError('selectEntity(' + entity + ') ' + e); } return false; } Thank you. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MochiKit" group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~----------~----~----~----~------~----~------~--~---