jquery - How to speed up an alert, Javascript -
i have created own add cart button , when user clicks button pops alert saying product added cart. have 3 categories of products , have created click event handler (pop-up alert) each one. problem seeing when user adds product cart, alert slow pop up. takes 10-20 seconds. there doing wrong?
<div class="productinfo"> <div class="producttitle"><?php echo $specialty1->specialty1 ?></div> <div class="buybutton"> <?php $producturl = producturl::find(array('product'=>$specialty1->specialty1)); if($producturl[0]->url!=null){ echo '<span id="add"><a id="add-link" href="' . $producturl[0]->url . '" data-role="button" data-inline="true" data-mini="true" data-theme="d" target="vspage" onclick="' . "_gaq.push(['_trackevent', 'buy now', 'specialty', '" . $specialty1->specialty1 . "'" . "]); _gaq.push(['_link', '" . $producturl[0]->url . "']);" . '">'; if($producturl[0]->button!=null){ echo $producturl[0]->button . '</a></span>'; }else { echo 'add cart</a>'; } } if($producturl[0]->url2!=null){ echo '<span id="add"><a id="add2-link" href="' . $producturl[0]->url2 . '" data-role="button" data-inline="true" data-mini="true" data-theme="d" target="vspage" onclick="' . "_gaq.push(['_trackevent', 'buy now', 'specialty', '" . $specialty1->specialty1 . "'" . "]); _gaq.push(['_link', '" . $producturl[0]->url2 . "']);" . '">'; if($producturl[0]->button2!=null){ echo $producturl[0]->button2 . '</a></span>'; }else { echo 'add cart</a>'; } } if($producturl[0]->url3!=null){ echo '<span id="add"><a id="add3-link" href="' . $producturl[0]->url3 . '" data-role="button" data-inline="true" data-mini="true" data-theme="d" target="vspage" onclick="' . "_gaq.push(['_trackevent', 'buy now', 'specialty', '" . $specialty1->specialty1 . "'" . "]); _gaq.push(['_link', '" . $producturl[0]->url3 . "']);" . '">'; if($producturl[0]->button3!=null){ echo $producturl[0]->button3 . '</a></span>'; }else { echo 'add cart</a>'; } } ?></div> <script type="text/javascript"> $(document).ready(function(){ $('a#add-link').click(function(event) { event.preventdefault(); var url = $(this).attr("href"); $.post(url, function () { alert("you added product cart."); }); }); $('a#add2-link').click(function(event) { event.preventdefault(); var url = $(this).attr("href"); $.post(url, function () { alert("you added product cart."); }); }); $('a#add3-link').click(function(event) { event.preventdefault(); var url = $(this).attr("href"); $.post(url, function () { alert("you added product cart."); }); }); }); </script>
the reason happening because sending request url takes while respond. you'll need optimize endpoints requesting in order make alert show faster - , you're still limited user's connection speed.
Comments
Post a Comment