微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – jquery ajax readystate 0 responsetext status 0 statustext error

我收到以下错误jquery ajax readystate 0 responsetext status 0 statustext错误给出它:url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm),但是当我给它url时它工作正常(localhost :我的localhost上的“”/“embparse_page”.

我已经尝试使用我在Google搜索中找到的标题,并且我使用了beforeSend:“”,但它仍然无效.

我认为主要问题是:XMLHttpRequest无法加载http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Access-Control-Allow-Origin不允许使用Origin“本地服务器”.但我不明白.

任何人都可以向我解释这个问题,因为我对此很陌生.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ng="http://angularjs.org">
<head>
    <Meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <Meta Access-Control-Allow-Origin="*" />
    <title>Page Parsing</title>
    <script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
    <script>
    getit=function(){
        jQuery.support.cors = true;
        $.ajax({
            type:"GET",
            url:"http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm",
            dataType:"html",
            crossDomain:true,
            beforeSend: function(xhr) {
                xhr.overrideMimeType('text/plain;charset=UTF-8');
            },
            success:function(XMLHttpRequest,jqXHR ,data) {
                //alert(data.title);
                var starttitl=data.lastIndexOf('<title>');
                var endtitl=data.lastIndexOf('</title>');
                var title1=data.substring(starttitl+7,endtitl);
                alert(title1);
            },
            error:function(errorStatus,xhr) {
                alert("Error"+JSON.stringify(errorStatus));
            }
        });
    }   
    </script>
</head>
<body>
    <div id="siteloader">
        <input type="button" onclick="getit()" />
    </div>
</body>
</html>

解决方法:

我得到了这个错误,在我的情况下,这不是由于相同的原始政策. This answer非常有帮助.

我的情况是,我有一个链接按钮,我没有使用e.PreventDefault()

ASPX

<asp:LinkButton ID="lnkSearch" runat="server" CssClass="DockCmdsearch" CommandName="Search" OnClientClick="return VerifySearch(this, event);" />

使用Javascript

function VerifySearch(sender, e) {        
    e.preventDefault();
    $.ajax({
                type: 'POST',
    .............
    }
    return false;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐