ie6-sending the JSONP request in the response function of the link click event does not take effect

Source: Internet
Author: User

1$ ("#link"). Click (function(){2 $.ajax ({3Type: ' GET ',4DataType: ' Jsonp ',5URL: ' Http://test.local.com/getdetail ',6Data:{id:1},7Successfunction(response) {8//IE6 do not perform9Alert ("JSONP success");Ten         }, OneErrorfunction(Request, status, error) { A              -         } -     }); the  -})

1. Phenomenon: Under IE6, send the script of the JSONP request, after establishing the HTTP connection, will stop sending the request, the problem is very strange, debugging for a long time can not find the reason. Google a bit, find the answer in StackOverflow (see other people's home and abroad question and answer site, is to force AH).

2. Solution: In the click Response function, call Evt.preventdefault (). If Evt.preventdefault () cannot perform (some special case), then call Jsonp with settimeout (guess, estimate no problem)

1$ ("#link"). Click (function(evt) {2 $.ajax ({3Type: ' GET ',4DataType: ' Jsonp ',5URL: ' Http://test.local.com/getdetail ',6Data:{id:1},7Successfunction(response) {8//IE6 can also perform9Alert ("JSONP success");Ten         }, OneErrorfunction(Request, status, error) { A              -         } -     }); the    //IE6 hack - Evt.preventdefault (); -})

Above transfer from http://blog.csdn.net/cwb0525/article/details/7744140

Resolves an issue where IE6 JSONP is not responding.

In the project development JSONP request in the Ie7,ie8,ff,chrome,safari wood has the problem.
Unread IE6 not come out results.

Later, the problem was found, and the method of calling this Jsonp was bound by an <a> tag's onclick event.

<a href= "javascript:;" onclick= "dothing ()" >jsonpRequest</a>


The problem is here.
where doting () is a method name that contains the JSONP request.
Here the href= "javascript:;" The original function is to let the user click on the time does not respond, do not let the browser jump back to the top, do not refresh the page.
But it also blocks Jsonp's callback function in IE6.
Cause the execution cannot continue.

The solution is to kill the href attribute. Just a bare <a> label would be fine.
As follows:
<a onclick= "dothing ()" >jsonpRequest</a>

The above content is transferred from http://www.cnblogs.com/didi/archive/2010/12/31/1923378.html

Depending on the two scenarios above, you can use a different label instead of a label, such as a span label

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.