0

Hi how do you insert the value of the name variable (inside the data object) inside html using jQuery?

Can you achieve this with jQuery? My code:

data = { // data object
    action: 'addMember',
    managerPassword: App.manager,
    name: $('#name_add').attr('value'),
    email: $('#email_add').attr('value')
};

$.ajax({
    url: App.URL_manager,
    data: data,
    dataType: 'json',
    type: 'POST',
    success: function(r) {
        if (r.success) {
            $('.add_staff').fadeOut(1000, function() {
                $('.success').find('#name').([INSERT VARIABLE HERE]);
                $('.success').fadeIn(1000);
            })
        }
        else {
            alert('you looser');
        }
    }
});​
0

5 Answers 5

1
$('.success').find('#name').html(data["name"]);
Sign up to request clarification or add additional context in comments.

Comments

1

Just use the . to refer object data, You do it like data.name:

success: function(r){
    if (r.success) {
        $('.add_staff').fadeOut(1000, function(){
            $('.success').find('#name').html(data.name);
        $('.success').fadeIn(1000);
        })
}

Comments

0
$('.success').find('#name').html(data);

1 Comment

Man, someone is having a bad day. What's with the serial down-votes?
0

Set attr

$('.success').find('#name').attr('disabled', 'disabled');

if you remove like

$('.success').find('#name').removeAttr('disabled');

Comments

-1
$('.success').find('#name').html( r.whatYouNeed );

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.