jQuery ajax跨域调用出现No Transport

时间:2021-08-28 19:47:04

在$.ajax之前添加代码  jQuery.support.cors = true;


    //之前没有加这句老是提示no transport,我没去深想。

    jQuery.support.cors = true;
        $.ajax
        ({
           
            type: "POST",
            contentType:
"application/x-www-form-urlencoded",
            dataType:
"html",
            url:
"http://www.*****.com",  //这里是网址
            success:
function(data){alert(data);},
            timeout:
30000,
            error:
function (XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
            }
        });

 

jquery.support.cors只是对CORS协议的一种实现,具体可以看jQuery的源代码,这里不多说。

附上几个很好的参考资料:
http://newhtml.net/using-cors/

http://www.kimhou.com/?p=222