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.

 

Link to comment
Share on other sites

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" );
});
Edited by Strider64
Link to comment
Share on other sites

  • 4 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.