HBuilder开发app ajax跨域 解决XMLHttpRequest

时间:2022-08-29 09:51:23

<div id="a1" onclick="testXHR()" style="font-size: 5em;">sss1</div>

   < script type = "text/javascript" >
           var data;
           var xhr=null;          
           function testXHR(){
               if(xhr){
                   return;
               }
               xhr=new plus.net.XMLHttpRequest();
               xhr.onreadystatechange=xhrStatechange;
               xhr.open( "GET", url);
               xhr.send();
           }
           function xhrStatechange(){
               if (xhr.readyState==4&&xhr.status == 200) {
                   
               
                       data = JSON.parse(xhr.responseText);
                   
                       
                   
            
                           
                       //alert(data.a1)   
                       for(i in data){alert(data[i])}
                                              
               
               }
           }
           
</ script >