Jump to content

How to stop page from going to top after ajax request


jasmeet

Recommended Posts

<script> 
$('.add_to').click(function(){
 //alert(1);
productId= $(this).attr('id');
//var grandTotal= $('#grandTotal').html('');
$('#sucessAdd').html('<img src="images/ajax-loader.gif" align="center" />');
      //var    grandTotalfloat=  parseFloat(grandTotal);
 
$.ajax({
             type: "POST",
             url:"pass.php",
              data: {action:'addCatalog',productId:productId},
             success:function(result){
//alert(result)
if(result==1){//add_to_cat
$('#'+productId).remove();
$('#'+productId).fadeTo("fast", .5);
$('#sucessAdd').html('');
//$('#sucessAdd').css('color','green');
$('#sucessAdd').addClass('add-sucess');
$('#sucessAdd_'+productId).html('<font coloe="red"><b>Add Successfully</b></font>');
$("#"+productId).style.display="block";
          
        }
})
});
</script>
 
 <div class="items_box_link"> <a href="#" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a>
        </div>
 
 
..........................................////////////////////////////............................................
 
 
after add to cart, my page goes to top but i want it to remain dere only..
 
any help!.. thanks.

 

Firstly, exclamation points on the Internet makes it seem like you're shouting, which in turn makes you sound ungrateful for any help I was trying to offer, even if it didn't help.

 

Can you post the code that you have now.

I'm only guessing but it might simple be fixed by doing this

 

Change this

<a href="#" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a>

to:

<a href="" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a>

I think the href="#" is causing the page to go to the top or you can disable it in script (which probably is the better of the two options and probably won't cause any problems)  :

 

I'm assuming you're using jQuery:

$(".add_to").on('click', function(e){
  e.preventDefault();
  $(this).removeAttr( "href" );
});
  • 4 months later...

Firstly, exclamation points on the Internet makes it seem like you're shouting, which in turn makes you sound ungrateful for any help I was trying to offer, even if it didn't help.

 

Can you post the code that you have now.

sorry.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.