Ajax problem XMLHttpRequest Status = 0

Source: Internet
Author: User

Ajax.html

<! DOCTYPE html>  

check.php

<?php
    $username = $_get[' username ');
    $password = $_get[' password ');
    if ($username = = ' 1 ' && $password = = ' 1 ') {
        echo 2;
    } else {
        echo 1;
    }
? >

XMLHttpRequest status = 0 issue.
Xmlhttp.readystate =4 The time, has been xmlhttp.status. = 200. Then the output, found in the Xmlhttp.status=0,http protocol but not the status code. Finally turn over Ah, find AH find Ah, finally found a XMLHttpRequest description: http://www.w3.org/TR/XMLHttpRequest/.
The status attribute must return the result of running these steps:
The value of status must return the result of running these steps.

1, if the state is unsent or opened, return 0. (If the status is unsent or opened, return 0)
2, if the error flag is set, return 0. (If the error label is set, return 0)
3. Return the HTTP status code.

If both of these cases occur before HTTP is returned, 0 is present.
First say two button, one is the URL is: file:///E:/test2.html, the other is: http://www.baidu.com.

The first button URL access is only local open not through the server, you can use Wireshark to catch the package (thanks to some expert pointing).
There is another problem in this, that is, xmlhttp.readystate will always change,
1: Server Connection established
2: Request received
3: In Request processing
4: The request is complete and the response is ready.
In this case, it should be XMLHTTP himself in the simulation, because there is no server. Open directly locally. Opened, so the status is 0.

The second button has URL access, although it is a different domain name, the catch is there, but this is a cross-domain access,
If The Cross-origin request status is network error

This is a network error.

Although go to visit, should be browser cross-domain return header is not allowed, so browser block,??????? Access-control-allow-origin this property.

The actual method is to access the URL within the domain of your own server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.