Javascript-Ajax cross-origin request and form submission events

Source: Internet
Author: User
Suppose there are now two websites, A and B, which provide services for the same user (C. Now, C logs on to the webpage provided by Company A and enters the user name and password in the login form. When you enter the user name, the browser asynchronously requests data. The available user name is displayed in real time below the form. The data is B website server... suppose there are now two websites, A and B, which provide services for the same user (C.
Now, C Login CompanyEnter the user name and password in the logon form.
When you enter the user name, the browser asynchronously requests data. The available user name is displayed below the form in real time. This data is returned by website B server (A does not have control of website B server ).
After the input is complete, press enter to trigger the form submission event. At the time of submission, the user name is sent to website A, and the password is locally hashed and then sent to website B.

The above implementation does not need to be detailed.

Reply content:

Suppose there are now two websites, A and B, which provide services for the same user (C.
Now, C LoginCompanyEnter the user name and password in the logon form.
When you enter the user name, the browser asynchronously requests data. The available user name is displayed below the form in real time. This data is returned by website B server (A does not have control of website B server ).
After the input is complete, press enter to trigger the form submission event. At the time of submission, the user name is sent to website A, and the password is locally hashed and then sent to website B.

The above implementation does not need to be detailed.

You can use the following two methods:

  1. Use CORS (Cross-origin resource sharing)
    You need to add CORS headers to the headers returned by website B's requests, and add the domain of website A to Access-Control-Allow-Origin. Cross-origin reference: http://blog.csdn.net/qgw_2000/article/details/8882051

  2. Send A request to website B through website A proxy
    Requests are sent to website A and forwarded to requests from website B. In nginx, you can simply use proxy_pass.

This is notxssWell, server B sets it to accept cross-domain requests from Domain.

If you understand the server configuration, we recommend that you use the second method on the second floor. If you do not understand it, you can also use php curl. The frontend forms are asynchronously submitted to site, site A accesses Site B through curl (or simulates the submission form) to obtain the data you want.

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.