andrewheins
andrewheins

Reputation: 798

jquery.post() and php

I'm using $().post and php to change the contents of a <textarea>.

The script is succeeding - firebug clearly shows that the text in between the textarea tags has changed, and my little alert fires.

The user, however, doesn't see the changes. In Firefox the change doesn't occur at all, and in IE, the textarea updates up to 10 seconds late.

Here's the jquery I'm using:

$(document).ready(function() {
    $('#pv_list li:first').addClass('hilite');
    $("input[name='db_entries']:first").attr('checked', 'checked');
    $("input[name='db_entries']").click(function () {
        $.post("changeEntry.php", {post: $(this).val()}, function(data) { 
            $("textarea").text(data);alert('done');
        });
        $('#pv_list li').removeClass('hilite');
        $(this).parent().addClass('hilite');
    });
});

At first I thought it was because the page didn't validate, but it validates xhtml transitional.

The thing that's really bugging me is I had it working earlier and can't figure out what I changed.

Upvotes: 1

Views: 824

Answers (4)

VolkerK
VolkerK

Reputation: 96159

Wouldn't it be easier to use the load() function?

$("input[name='db_entries']").click(function () {
    $("#outputarea").load("?", {"paramName":this.value});
});

Upvotes: 0

Thomas
Thomas

Reputation: 4999

I'm not sure, but one possibility is that you should do:

function(data){
  $("textarea").attr("value",data);
  alert('done');
}

Upvotes: -2

tvanfosson
tvanfosson

Reputation: 532435

Have you tried using val() to set the value of the textarea instead of text()?

$.post("changeEntry.php",{post: $(this).val()},
      function(data) {
          $("textarea").val(data);
          alert('done');
});

Upvotes: 3

Related Questions