Solve the problem of the inexplicable interruption of jquery Ajax requests in IE6 _jquery

Source: Internet
Author: User

Scene Restore: Bind a Click event to the a tag to trigger the AJAX request, in IE6, the request is often interrupted and all is normal in IE6.

<a href= "javascript:;" id= "btn" >click me</a> <script type=
"Text/javascript" src= "Jquery.js" > </script>
<script type= "Text/javascript" >
 var url = "http://api.flickr.com/services/"
 feeds/photos_public.gne?tags=car& "
 tagmode=any&format=json&jsoncallback=?";
 $ ("#btn"). Click (function () {
  $.getjson (URL, function (data) {
   alert (data);})
 ;
</script>

In IE6 use Fiddler2 monitoring request, often appear "aborted", toss for a long time, quite strange. Later, the a label was replaced with a button, the request was normal, and the last reminder may be that the default event for a label interrupted the request. However, in the HTML code, the href of a label has been set to "javascript:;", which is usually the way to block the default event (page jump). The Click event of a label executes before the href jump is executed, and if HREF is a JavaScript statement, it executes at this time. IE6 interrupts the AJAX request triggered by the click when it executes the JavaScript statement for href. Use href= "javascript:;" To prevent the default event, moving the action that prevents the default event to the Click event resolves the problem so that the JavaScript statement in HREF is not executed.

$ ("#btn"). Click (function (e) {
 $.getjson (URL, function (data) {
  alert (data);
 E.preventdefault ();
});

Note:e.preventdefault (); The function of this sentence is to prevent the default events in JS.

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.