Inserting text into a textarea using .load() in jQuery

Posted by bateman_ap on Stack Overflow See other posts from Stack Overflow or by bateman_ap
Published on 2010-05-14T17:03:04Z Indexed on 2010/05/14 17:04 UTC
Read the original article Hit count: 159

Filed under:

Hi, having a bit of a nightmare, I am trying to use jQuery to insert some text taken from a .load() call into a form field (textfield) after a user logs in (basically prefilling some known details)

The code I am using is:

$.ajax({
        type: "POST",
        url: "/ajax/login.php",
        data: dataString,
        success: function(html) {
            if (html == 1) {
                $("#loginPanel").load("/ajax/login-panel.php");     
                $("#bookName").load("/ajax/getSessionDetails.php #userUsername");
                $("#bookEmail").load("/ajax/getSessionDetails.php #userEmail"); 
                $("#bookingLogin").hide("fast"); 
            } else {
                $("#loginError").html("Sorry, login failed, please try again");
            }
        }
    });

If I hardcode such as $("#bookName").html("Test Content"); it works OK so it must be a problem with the .load call.

I looked around and found some guy suggest something like the following code but I couldn't get it to work:

$.get(htmlBannerUrl, function(data){
  $('textarea').val(data);
});

© Stack Overflow or respective owner

Related posts about jQuery