JS 操作 HTML 和 AJAX 请求后台数据

Posted float123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS 操作 HTML 和 AJAX 请求后台数据相关的知识,希望对你有一定的参考价值。

为某个元素插入值,添加属性,添加子元素

  1 <div class="col-sm-6">
  2    <select class="form-control" id="creategood_store">
  3    </select>
  4  </div>
  1  var parent = document.getElementById("creategood_store");
  2  var node = document.createElement("option");
  3  node.setAttribute("value", data.result[i].id);
  4  node.innerhtml = data.result[i].name;
  5  parent.appendChild(node);

AJAX 请求后台数据

  1   $(document).ready(function () {
  2         $.ajax({
  3             url: "/gankadc/home/newlydata/recordlist",
  4             type: "GET",
  5             dataType: "json",
  6             success: function (data) {
  7 		...
  8 	    }
  9 
 10         })
 11     });
 12 

以上是关于JS 操作 HTML 和 AJAX 请求后台数据的主要内容,如果未能解决你的问题,请参考以下文章