jquery ajax readystate 0 responsetext status 0 statustext error

前端 未结 5 1429
执念已碎
执念已碎 2020-11-28 14:21

I am getting the following error: jquery ajax readystate 0 responsetext status 0 statustext error when giving it: url(http://www.tutorialspoint.com/proto

相关标签:
5条回答
  • 2020-11-28 14:49

    same origin policy. the browser does not allow when you're on

    http://site1.com
    

    to connect to:

    site2.com
    sub.site1.com
    site1:99.com
    https://site1.com (not sure about this one)
    

    This is so site1 cannot steal content from site2 and pretend it's the content of site1. Ways around this is JSONP (google maps use that I think) and having site2 provide cors headers but cors are not supported in jQuery 1.* (maybe not in 2.* either) because IE has some problems implementing it. In both situations you need site2 to cooperate with your site so your site can display it's content.

    If you only use this yourself then you can use Firefox and install the forcecors plugin. To activate you can choose view => toolbars => add on bar and click on the text "cors" in the right bottom of the screen.

    0 讨论(0)
  • 2020-11-28 14:49

    I was testing reading a txt/XML file for json/xml data and got an error... the values read: Status[0] & readyState[0] and StatusText[error]; This was working successfully on Internet explorer but not on Chrome because the domain needed to be the same

    This is what fixed it

    Go to C:\WINDOWS\system32\drivers\etc\hosts

    Put a name against your localhost app:

    127.0.0.1   SampleSiteName.com
    

    Now open the code in chrome as http://SampleSiteName.com/YourAjaxFileName.htm (if it opens, it means that you have entered a host name correctly) go to your HTML file and give a relative address of the file which you are trying to read (if FileToBeRead.txt is in the same folder as YourAjaxFileName.htm, then just enter url: "/FileToBeRead.txt")

    Now your code will work on Chrome as well.

    0 讨论(0)
  • 2020-11-28 15:02

    I was getting that error from my Ajax call, and what fixed it for me was just putting in the 'return false'.

    0 讨论(0)
  • 2020-11-28 15:07

    I had same problem with Nginx ( server side ) and AngularJs ( User side )
    as other developer said its Cors problem , here i just want to say how i solve my problem maybe some one use this approach ;)
    first I added below lines to my Nginx config files( in linux -> /etc/nginx/sites-available/your domain) :

        add_header Access-Control-Allow-Origin *;
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    and with angularJs I send my request like this :

            $http({
                method: "POST",
                data: { //params},
                url: "//address",
                headers: { //if its form data
                    "Accept": "application/json",
                    "Content-Type": "application/x-www-form-urlencoded",
                    "Cache-Control": "no-cache"
                },
                crossDomain: true,
                contentType: false,
                processData: false
            }).then(function mySucces(response) {
                alert(JSON.stringify(response));
            }, function myError(response) {
                alert("error");
            });

    0 讨论(0)
  • 2020-11-28 15:10

    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;
    }
    
    0 讨论(0)
提交回复
热议问题