zoukankan      html  css  js  c++  java
  • 原生JS请求(AJAX)

    页面内容

    <!DOCTYPE html>
    <html>
    <body>
    
    <h1>XMLHttpRequest 对象</h1>
    
    <p id="demo"></p>
     
    <script>
    
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function(res) {
        if (this.readyState == 4 && this.status == 200) {
        //object
        var text = JSON.parse(this.responseText);
        //string
        //var text = this.responseText;
        console.log(text);
        }
      };
      var cid = 1001;
      xhttp.open("POST", "http://xxx.com", true);
      xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhttp.send("cid="+cid+"&id=1111&fname=1234");
      
    </script>
    
    </body>
    </html>

     服务器

    <?php
    
    namespace appindexcontroller;
    use thinkRequest;
    use thinkController;class Index extends Controller
    {
        public function index(Request $request)
        {
            
            $response = new Response;
            // ajax 原生JS请求
            $data = $request->param();
            return json($data, 200, ['Access-Control-Allow-Origin' => '*']);
      }
    }
  • 相关阅读:
    洛谷P2751 工序安排Job Processing
    UVA 1613 K度图染色
    线段树+扫描线
    分组背包
    洛谷P5506 封锁
    洛谷P2574 XOR的艺术
    List.Sort
    Dict.Count
    Convert.ToString(null) => null
    Convert 输入字符串的格式不正确
  • 原文地址:https://www.cnblogs.com/xuanjiange/p/12880987.html
Copyright © 2011-2022 走看看