Send POST request full case with native Ajax

Source: Internet
Author: User

Using AJAX to send data to the front and back of the interaction, I think is the most basic web development skills. DZ Development recently because not compatible with jquery, so can only use native JS to send data, do not want to encounter many problems. Here is a summary of the analysis. Let's start with a case that uses Ajax to send post form data.


index1.php

<?phpif (!empty ($_post)) {echo json_encode ($_post);}

There are a few things to note.

1:ajax cannot request data across domains: When cross-domain: If the current script domain name is: locakhost/index.php, the requested URL is 127.0.0.1, the send request fails, or the server can receive the request, but xmlhttp.status= 0, the browser does not accept data returned by the server.

What is a cross-domain? Cross-domain How to send request data, this blog has a good explanation.

Http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html#m0


2: When sending a request with a For loop, Ajax can only receive the last requested data because the for loop is much faster than the speed at which a request is completed.

3: The json,php function Json_encode () and Json_decode () can only accept strings encoded in UT8 format, and no returns NULL.

Send POST request full case with native Ajax

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.