Question

I've two hyperlinks. I'm hiding the one hyperlink on the click of other hyperlink and vice-versa. It's working absolutely fine for me on my local machine. But the issue arises when I upload and run the same functionality from the online server.

On server, the concerned hyperlink is not hiding that much quicker as compared to local machine instance. Due to which user can click again on a hyperlink which he has already clicked and the link is expected to be hidden. It takes moment or two for hiding the concerned hyperlink. I don't want that delay. The hyperlink should get hide immediately after on click event. I tried disable/enable the hyperlink but it didn't work out for me.

My code is as below:

<script language="javascript" type="text/javascript">
$(".fixed").click(function(e) { 
    var action_url1 = $(this).attr('delhref');
    var qid = $(this).data('q_id');


    $(".fixed").colorbox({inline:true, width:666});

    $("#fixedPop_url").off('click').on('click',function(event) {
      event.preventDefault();
      $.get(action_url1, function(data) {

        //$("#fix_"+qid).bind('click', false);
        $("#fix_"+qid).hide();//This portion of code I want to make fast, it's taking some time to hide and meanwhile user can click on this link. I want to avoid it.
        $("#notfix_"+qid).show();
        //$("#notfix_"+qid).bind('click', true);
        alert("Question status updated successfully");

      });      
    });       

    $(".c-btn").bind('click', function(){
      $.colorbox.close();
    });
  });

  $(".notfixed").click(function(e) { 
    var action_url2 = $(this).attr('delhref');
    var qid = $(this).data('q_id');

    $(".notfixed").colorbox({inline:true, width:666});

    $("#notfixedPop_url").off('click').on('click',function(event){
      event.preventDefault();
      $.get(action_url2, function(data) {

        //$("#notfix_"+qid).bind('click', false);
        $("#notfix_"+qid).hide();//This portion of code I want to make fast, it's taking some time to hide and meanwhile user can click on this link. I want to avoid it.
        $("#fix_"+qid).show();
        //$("#fix_"+qid).bind('click', true);
        alert("Question status updated successfully");

      });       
    });
</script> 
Was it helpful?

Solution

You dont have to write the hide part code in complete function of get request. On live it will take time to fetch the rspond.so just keep it outside get function.something like this:

 $(".fixed").click(function(e) { 
    var action_url1 = $(this).attr('delhref');
    var qid = $(this).data('q_id');
    $("#fix_"+qid).hide();
    //rest code......
 });
 $(".notfixed").click(function(e) { 
    var action_url2 = $(this).attr('delhref');
    var qid = $(this).data('q_id');
    $("#notfix_"+qid).hide();//hide it here
    //rest code......
 });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top