Cross-origin problem occurs when Ajax accesses the PHP page. ajaxphp

Source: Internet
Author: User

Cross-origin problem occurs when Ajax accesses the PHP page. ajaxphp

1. Cross-origin problem: Simply put, the program under Domain A wants to obtain information from the file under Domain B (this sentence is what I see online)

2. General request (local test): The response page of the Request page is normal. However, if I change the url of the Ajax request to http: // 127.0.0.1/TestJQ/Test1/ajax. in php, the console reports XMLHttpRequest cannot load http: // 127.0.0.1/TestJQ/Test1/ajax. php. no 'access-Control-Allow-origin' header is present on the requested resource. origin 'HTTP: // localhost' is therefore not allowed access. this is the cross-origin issue. If we add a header to the response page, of course, header ("Access-Control-Allow-Origin: *"); "*" indicates that all requests to all websites Allow us to use the specified URL, indicating that only These website requests are allowed. In fact, why is the URL changed to http: // 127.0.0.1/TestJQ/Test1/ajax. php will cause cross-origin, but I still cannot figure it out. After all, the request page and response page are under the Apache server directory of my computer, and it is still troublesome for me to pass through the instructions. Thank you ~~
How to Implement php ajax proxy cross-origin login?

Use session or cookie. After successfully logging on to a. php, pass the session value to a1.php and a1.php to B. php.
Use a special user id as the value. For example, the id is 1, flag1, and B. php checks whether such a session or cookie exists.

Does AJAX support cross-origin access? If not, what is the solution?

Write a collector in PHP, AJAX submits the request to this collector, and then the collector sends the request to JSP. Return the data to the foreground.

Just like a collection program. It is stored in the database. You directly sent the message to the front-end.
 

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.