zoukankan      html  css  js  c++  java
  • 9.5 jsonp 实现


    server
    const http = require('http') const url = require('url') http.createServer((req,res) => { let msg = '服务端消息' res.writeHead(200,{"Content-Type": "text/plain;charset=utf-8"}) //拿到请求数据 let URL = url.parse(req.url,true) let callback = URL.query.callback //console.log(callback) res.write(`${callback}("${msg}")`) res.end() }).listen(3000, () => { console.log('开启服务端') })

      

    user-agent
    
    <button class="btn">发送</button>
      <script>
        function show(params) { 
          alert(params+'拿到了')
          let sc = document.querySelector('script:last-child')
          //删除新加的
          document.getElementsByTagName('body')[0].removeChild(sc)
          
        }
        let btn = document.getElementsByClassName('btn')[0]
        btn.addEventListener('click',() => {
        let sc = document.createElement('script')
        sc.src = `http://localhost:3000?callback=show`
        document.getElementsByTagName('body')[0].appendChild(sc)
        
        //console.log( document.getElementsByTagName('body'),sc)
       })
      </script>
    

      

  • 相关阅读:
    全球化编码
    linuxGrep命令
    Xcode-插件所在路径
    多控制器间数据传递
    触摸事件
    IOS事件处理
    事件监听的三种方法
    UITabBarController
    聊天布局
    Info.plist:项目配置文件
  • 原文地址:https://www.cnblogs.com/zjj-study/p/13618498.html
Copyright © 2011-2022 走看看