Home  >  Article  >  Web Front-end  >  Ajax implements the function of loading data

Ajax implements the function of loading data

亚连
亚连Original
2018-05-22 14:18:351207browse

This article mainly introduces the ajax function of loading data in detail, which has certain reference value. Interested friends can refer to the specific code of

for your reference. The content is as follows

#1.xssj.php

<script src="jquery-3.2.0.min.js"></script>
<title>无标题文档</title>
</head>

<body>
<h1>显示数据</h1>
<select id="sel">

</select>
<input type="button" value="取选中值" id="qu" />
</body>
<script type="text/javascript">
$(document).ready(function(e) {
  
  //异步AJAX :执行chuli页面的同时,继续执行下面代码。效率高,不用等待,继续执行下面代码
  //异步和同步 同步:效率不高,不能同时执行两件事情
  $.ajax({
    //async:false,//把异步关闭,相当于开启同步
    url:"xschuli.php",
    dataType:"TEXT",
    //complete: function(){},//执行完成之后执行
    //beforeSend: function(){},//发送处理请求之前,自动处理此方法 complete和beforeSend可以实现进度条
    //error: function(){},//如果出错了执行此方法
    success: function(data){ //success: function(){}是执行完成之前执行
      var hang = data.split("|");
      var str = "";
      for(var i=0;i<hang.length;i++)
      {
       var lie = hang[i].split("^");
       str = str+"<option value=&#39;"+lie[0]+"&#39;>"+lie[1]+"</option>";
      }
      $("#sel").html(str);
      //alert($("#sel").val());
     }
   });
   
   //alert($("#sel").val());
   
   $("#qu").click(function(){
     alert($("#sel").val());
    })
});
</script>
</html>

2.xschuli.php

<?php
require "DBDA.class.php";
$db = new DBDA();
$sql ="select * from nation";
//$arr = $db->query($sql,1);
//var_dump($arr);
"n001^汉族|n002^壮族|n003^维吾尔族";
echo $db->strquery($sql);
/*$str="";
foreach($arr as $v)
{
 $str = $str.implode("^",$v)."|";
}

$str = substr($str,0,strlen($str)-1);

echo $str;*/

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solution for Ajax request to be sent successfully but not succeed (graphic tutorial)

Struts2 and Ajax data Interaction (graphic tutorial)

MUi framework ajax request WebService interface instance_AJAX related

The above is the detailed content of Ajax implements the function of loading data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn