ajax - Inserting html with jquery doesn't work -


i'm building simple shoutbox.

here's 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 

>

here's js code :

$(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);             }         });     } }); 

but apparently messagelist.html(data["response"]) doesn't work although firebug shows response :

{"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>"}

if instead of success in ajax have complete var data = json.parse(data); error. ideas can changed fix issue ?

update :

adding:

    var c = data["response"];     console.log(c); 

gives me :
<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> in firebug console.

nobody else noticed error in html.

<div class=".shoutbox"> 

should be:

<div class="shoutbox"> 

fix , see if jquery stuff works.

edit mentioned in other answers should set response type json. avoid having use json.parse() on data. isn't necessary given use of json.parse() on response data.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -