CHAT MDL-8224, use json encoded success message
authorDongsheng Cai <unoter@gmail.com>
Tue, 14 Sep 2010 07:33:40 +0000 (07:33 +0000)
committerDongsheng Cai <unoter@gmail.com>
Tue, 14 Sep 2010 07:33:40 +0000 (07:33 +0000)
mod/chat/chat_ajax.php
mod/chat/gui_ajax/module.js

index 02a1df9..1d31fc1 100644 (file)
@@ -16,6 +16,8 @@
 
 //TODO: use standard CLI_SCRIPT support here (skodak)
 
+define('AJAX_SCRIPT', true);
+
 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
 require_once(dirname(__FILE__) . '/lib.php');
 
@@ -85,7 +87,8 @@ case 'chat':
 
         $DB->insert_record('chat_messages', $message);
         $DB->insert_record('chat_messages_current', $message);
-        echo 200;
+        // response ok message
+        echo json_encode(true);
         add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
 
         ob_end_flush();
index 08b2558..23a23e6 100644 (file)
@@ -167,10 +167,13 @@ M.mod_chat_ajax.init = function(Y, cfg) {
         },
 
         send_callback : function(tid, outcome, args) {
-            if (outcome.responseText == 200) {
-                this.sendbutton.set('value', M.str.chat.send);
-                this.messageinput.set('value', '');
+            try {
+                var data = Y.JSON.parse(outcome.responseText);
+            } catch (ex) {
+                return;
             }
+            this.sendbutton.set('value', M.str.chat.send);
+            this.messageinput.set('value', '');
             clearInterval(this.interval);
             this.update_messages();
             var scope = this;
@@ -180,7 +183,6 @@ M.mod_chat_ajax.init = function(Y, cfg) {
         },
 
         talkto: function (e, name) {
-            console.info(name);
             this.messageinput.set('value', "To "+name+": ");
             this.messageinput.focus();
         },