Home>

The first file:html

<! Doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>ajax solve cross-domain issues</title>
  <script src="jquery-3.0.0.min.js" type="text/javascript"></script>
</head>
<body>
<script>
  $.ajax ({
    type:"post",    url:"postdemo.php",    data:{
      "url":"http://192.168.4.101:90/phpstudy4/server.php",      "username":"admin",      "password":"admin",    }, success:function (data) {
      var result=eval ("(" + data + ")");
      console.log (result);
    }
  })
</script>
</body>
</html>

The second file:Server-side processing data

<?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"));

Among them "url":"http://192.168.4.101:90/phpstudy4/server.php", this url is our remote access address.

  • Previous First contact with the magical Bootstrap form
  • Next NodeJS and HTML5 combined implementation method of dragging multiple files to upload to the server