首页 > 技术文章 > Ajax使用

zpblogs 2018-06-25 17:12 原文

var path = "{%#path%}";//当前路径(公司写法)
var url = path + "?xmls=xmls/news.xmls&method=fangansxx";//URL路径
 $.ajax({
   async:false,//同步或异步 false同步执行,默认为异步true
   type: 'post',//请求方式
   url: url,//URL路径
   success: function (ret) {
     $("#BodyText2").html(ret)//添加至页面
  }
})
var path = "{%#path%}";
var url = path + "?xmls=xmls/news.xmls&method=cpleibies3";
   $.ajax({
   type: 'post',
   url: url,
   data:nei,
   async: false,
   success: function (ret) {
      if (ret != "no") {
         var json = JSON.parse(ret);
         $.each(json, function (index, item) {
         var html = "<a href=\"javascript:;\" class=\"xx\" id=\"biao_" + item.CatalogId + "\" onclick=\"tiaozhuan(" + item.CatalogId + ")\">" + item.CatalogName + "</a>";
         $("#h1").append(html);
      })
      }
  }
})
var path = "{%#path%}";
var url = path + "?xmls=xmls/product.xmls&method=cpleibies";
$.ajax({
  type: 'post',
  url: url,
  async: false,
  success: function (ret) {
    if (ret != "no") {
       var json = JSON.parse(ret);
       $.each(json, function (index, item) {
         var carlist = "";
         var url = path + "?xmls=xmls/product.xmls&method=cpleibies2&cid=" + item.CatalogId + "";
         $.ajax({
           type: 'post',
           url: url,
           async: false,
           success: function (rets) {
           var carjson = JSON.parse(rets);
           $.each(carjson, function (carindex, cars) {
           carlist += "<li class=\"hsl-li\" ><a class=\"foz14 colo7c text-left\" onclick=\"tiaos(" + cars.ProductId + ")\">" + cars.ProductName + "</a></li>";
           })
         }
     })
      var html = "<a style=\"margin-left:1%\"  href=\"javascript:;\" onclick=\"ic(" + item.CatalogId + ")\">" + item.CatalogName + "</a>";
      $("#hv").append(html);
     })
   } else {
     layer.msg("加载失败!", { time: 3000 });
    }
   }
 })
})

 

推荐阅读