asp.net mvc 4 - how can I change content in span after ajax success in MVC 4 -


<div>   <span class="label">1</span>   <a href="#" class="click">up</a> </div> 

javascript

$('.click').click(function(){ //$(this).parent().find('.label').html(2); $.ajax({     ....     success: function(result){     $(this).parent().find('.label').html(2);     } }); 

});

if don't use ajax.post, value in change.. , when use, doesn't change.

i don't know happen? , how can fix it.

give me advices please.

$(this) not referring link (its inside $.ajax() function). assign label element javascript variable before make ajax call can accessed inside ajax function.

$('.click').click(function(){   var label = $(this).parent().find('.label');   // or $(this).prev('.label');   $.ajax({     ....     success: function(result){       label.html(2);    } }); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -