jQuery ajax跨域调用出现No Transport

在$.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

猜你喜欢

转载自blog.csdn.net/weixin_42776027/article/details/102950244
今日推荐