Ajax remote communication and ajax Remote Communication

Source: Internet
Author: User

Ajax remote communication and ajax Remote Communication

The examples in this article share with you how ajax achieves remote communication for your reference. The specific content is as follows:

First file:Html

<! DOCTYPE html> 

 The second file:Server-side Data Processing 

<?php/** * Created by PhpStorm. * User: Administrator * Date: 2016-7-21 * Time: 10:12 */if ($_SERVER["REQUEST_METHOD"] == "POST") {//  echo json_encode(array("111"=>"112"));  if (isset($_POST["url"]) && isset($_POST["username"]) && isset($_POST["password"])) {    $result = postDemo($_POST["url"], array("username" => $_POST["username"], "password" => $_POST["password"]));    echo $result;  } else {    echo json_encode(array("msg2" => "!!!!!!!!!!!!!!!!!!!!!error!!!!!2"));  }} else {  echo json_encode(array("msg" => "error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));}function postDemo($url, $data){  $query = http_build_query($data);  $options = array(    "http" => array(      "header" => "Content-type: application/x-www-form-urlencoded\r\n" .        "Content-length:" . strlen($query) . "\r\n" .        "User-Agent:MyAgent/1.0/r/n",      "method" => "POST",      "content" => $query    )  );  $content = stream_context_create($options);  $result = file_get_contents($url, false, $content);  return $result;}//echo postDemo("http://192.168.4.101:90/PHPStudy4/server.php",array("username"=>"admin","password"=>"admin"));

"Url": "http: // 192.168.4.101: 90/PHPStudy4/server. php", which is the access address to the remote end.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.