Adam Ramadhan
Adam Ramadhan

Reputation: 22810

get a spesific html on return jquery ajax post

$('#form-register').change(function() {
    var i_username = $('input#input-username').val();
    var i_password = $('input#input-password').val();
    var i_company  = $('input#input-company').val();
    var i_phone    = $('input#input-phone').val();
    $.post("home", { 
        username : i_username,
        password : i_password,
        company  : i_company,
        phone    : i_phone,
        register : 'helloworld' 
    }, function(return_data){
        $('body').html(return_data);
    });
});

ok the question maybe is on the $('body').html(return_data); can we get a specific html from the return data ? example #errordiv that contains my error list if exist then somehow append on my page ? or is there another better way to do it ?

Thanks for looking in,

Adam Ramadhan

Upvotes: 2

Views: 757

Answers (2)

Harish
Harish

Reputation: 2324

yes u can append errordiv

<ul id="tmp">
<li>Name</li>
<li>Address</li>
</ul>

then use

$('<li>Error</li>').prependTo('#tmp');

will give

<ul id="tmp">
    <li>Error</li>
<li>Name</li>
<li>Address</li>
</ul>

Upvotes: 0

Falcon
Falcon

Reputation: 1463

$(return_data) will give you html structure

and $(return_data).find('#errordiv') will give you "error div" element

Upvotes: 1

Related Questions