0

I've been working on a project that involves ajax; it's a planner for school assignments. When a button is pressed, it's supposed to change the text inside of 31 <textarea>'s (and one <span>) based on data it gets from the server. The thing is, textareas that have been changed after the last time the window was refreshed don't change. I've looked over the JSON sent between the server and the webpage and vice-versa, and concluded that the bug is in the success function of the ajax call. Here's the code:

  success: function(data) {                
    $("span#date").text(data['date']);
    $("#assignments").find("textarea").each(function() {
      $(this).text("");
      $(this).html(data[$(this).attr("id")]);
    });
    console.log(data); // I was using this to see if the data received from the server was correct
  }

Thanks very much in advance for any help.

4

2 に答える 2

1

you should use .val() for textarea as it's basically an input.

You can't really have html elements inside it.

于 2012-09-01T19:39:32.200 に答える
0

Try $(textarea).val() instead of .html(). I noticed that html only works the first time the textarea is rendered.

于 2012-09-01T19:45:30.313 に答える