【问题标题】:How can I run a httprequest inside function first thing before page loads?如何在页面加载之前首先在函数内部运行 httprequest?
【发布时间】:2020-08-02 00:40:19
【问题描述】:

我试过在body标签中加载属性没有成功

<body onload=\"updateGroup()\">

也不是在 echo 中调用函数: echo "<script> updateGroup(); </script>";

我愿意接受批评!

function updateGroup(){
            
            var http = new XMLHttpRequest();
            var url = \"../requests/updateGroup.php\";
            http.open(\"POST\", url, true);

            //Send the proper header information along with the request
            http.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");

            http.onreadystatechange = function() {//Call a function when the state changes.
              if(http.readyState == 4 && http.status == 200) {
                
              }
            }
            http.send();
          }

【问题讨论】:

    标签: javascript php html xmlhttprequest


    【解决方案1】:

    我相信您正在寻找的是iife。这甚至应该在 document.ready 之前运行

    (updateGroup() {
     ....
    })();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 2017-01-13
      相关资源
      最近更新 更多