Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

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). It is #bookName and #bookEmail I am having problems with

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);
});
like image 520
bateman_ap Avatar asked Jun 27 '26 04:06

bateman_ap


1 Answers

You can also use text();

$('#loginError').text();
like image 56
sundowatch Avatar answered Jun 30 '26 13:06

sundowatch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!