Я строю простой чат.
Вот HTML:
<div id="shoutbox">
<form method="post" id="form" class="shoutbox-form">
<table>
<tr>
<td><label>User</label></td>
<td><input class="text user" id="nick" type="text" MAXLENGTH="25" /></td>
</tr>
<tr>
<td><label>Message</label></td>
<td><input class="text" id="shout" type="text" MAXLENGTH="255" /></td>
</tr>
<tr>
<td></td>
<td><input id="send-shout" type="submit" value="Dodaj!" /></td>
</tr>
</table>
</form>
<div id="shoutbox-container">
<span class="clear"></span>
<div class=".shoutbox">
<div id="shoutbox-loading"><img src="css/images/loading.gif" alt="Loading..." /></div>
<ul>
</ul>
</div>
</div>
</div
>
Вот код js:
$(document).ready(function(){
var inputUser = $("#nick");
var inputMessage = $("#shout");
var loading = $("#shoutbox-loading");
var messageList = $(".shoutbox > ul");
function updateShoutbox(){
messageList.hide();
loading.fadeIn();
$.ajax({
type: "POST",
url: "/shouts/",
data: "action=refresh",
success: function(data){
var data = JSON.parse(data);
loading.fadeOut();
messageList.html(data["response"]);
messageList.fadeIn(2000);
}
});
}
});
Но, очевидно, messageList.html (data ["ответ "]) не работает, хотя firebug показывает, что мой ответ:
{"response": "<li><strong>user1</strong><img src=\"\" alt=\"\" >test<span class=\"date\">2010-10-07 19:36:13</span></li><li><strong>user2</strong><img src=\"\" alt=\"\" >test2<span class=\"date\">2010-10-07 20:23:56</span></li>"}
Если вместо success
в ajax у меня complete
, я получаю var data = JSON.parse(data);
ошибку,Любые идеи, что можно изменить, чтобы решить эту проблему?
ОБНОВЛЕНИЕ:
Добавление:
var c = data["response"];
console.log(c);
Дает мне:
<li><strong>user1</strong><img src="" alt="" >test<span class="date">2010-10-07 19:36:13</span></li><li><strong>user2</strong><img src="" alt="" >test2<span class="date">2010-10-07 20:23:56</span></li>
в консоли Firebug.