Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
939 views
in Technique[技术] by (71.8m points)

javascript - jquery ajax readystate 0 responsetext status 0 statustext error

I am getting the following error: jquery ajax readystate 0 responsetext status 0 statustext error when giving it: url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm), however it's working fine when I give it url(localhost:""/embparse_page) on my localhost.

I have tried using the headers which I found on a Google search, and I have used beforeSend:"" too, but it's still not working.

I think the main problem is: XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin. but I don't understand it.

Can anyone please explain the problem to me, as I'm quite new to this.

<!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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was getting this error and in my case it was not due to same origin policy. This answer is quite helpful.

My case was, I had a link button and I was not using 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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...