【皇家赌场手机版】Helper或Jquery异步加载部分视图,ajax完结产品页面加载音信

按需加载的优势:在实质上考查中开采,大多的网友在出境游网址时有所无可争辨的指向性,往往在进入主页后直接寻觅进入自身要求的商品列表内,假使在客户进入主页时将主页音信全体加载完结后出示给消费者,会大幅度的荒废网址财富,同时也会稳中有降客户体验度,由此按需加载则成为了当今网址创设的主流。

先给大家显示效果图:

js

废话不多说了,直接给我们贴代码了。

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>按需加载图片</title>

<style type="text/css">

*{margin:0px;padding:0px;list-style:none;}

ul{

height:auto;

overflow:hidden;

width:400px;

margin:0 auto;

}

li{

width:300px;

height:200px;

border:solid 1px #ddd;

overflow:hidden;

}

</style>

</head>

<body>

<ul>

<li><img data-src="./sunli/1.jpg" alt="皇家赌场手机版 1" width="100%"></li>

<li><img data-src="./sunli/2.jpg" alt="皇家赌场手机版 2" width="100%"></li>

<li><img data-src="./sunli/3.jpg" alt="皇家赌场手机版 3" width="100%"></li>

<li><img data-src="./sunli/4.jpg" alt="皇家赌场手机版 4" width="100%"></li>

<li><img data-src="./sunli/5.jpg" alt="皇家赌场手机版 5" width="100%"></li>

<li url="./rexiao.php">



</li>

</ul>

<script type="text/javascript" src="jquery-1.8.3.min.js"></script>

<script type="text/javascript">

//绑定窗口的滚动事件

$(window).scroll(function(){

//遍历检测里面的元素尺寸

$('li[isLoaded!=1]').each(function(){

//获取滚动高度

var sT = $(window).scrollTop();

//获取窗口的可视区域的高度

var cT = $(window).height();

//获取元素距离文档顶部的偏移量

var t = $(this).offset().top;

//暂存当前元素对象

var curLi = $(this);

//检测判断

if(t <= sT + cT){

//检测是否具有url属性

var url = $(this).attr('url');

//如果有 发送ajax 获取请求之后的数据

if(url){

//发送ajax

$.get('rexiao.php',{}, function(data){

curLi.html(data);

return;

})

}

//这个时候要显示了 修改元素的src属性 

var src = $(this).find('img').attr('data-src');

//设置

$(this).find('img').attr('src',src);

//做标识

$(this).attr('isLoaded','1');

}

})

})

​

//使用代码来触发滚动事件 

$(window).trigger('scroll');

</script>

</body>

</html>

皇家赌场手机版 6

//加载页面

//加载产品列表
function GetProductList() {
  function PostParam(param) {
    param.key = "lm324";
    return param;
  }
  var PostExecParam = {
    ClassName: "AnxinE.BLL.Product.ProductInfoBLL",
    MethodName: "Search",
    ParamModelName: "AnxinE.Model.Product.ProductInfoParam",
    onRequest: PostParam,
    onResponse: function (result) {
      if (result != null) {
        var html = "";
        //汇率判断
        //<td>" + (result.SupplierProductList[i].ProductList[j].PriceUSD.toString() == '0' ? 1 : result.SupplierProductList[i].ProductList[j].USDPriceList[0].MinQuantity) + ":" + result.SupplierProductList[i].ProductList[j].PriceUSD + "</td>
        //展示搜索-产品信息列表
        for (var i = 0; i < result.SupplierProductList.length; i++) {
          for (var j = 0; j < result.SupplierProductList[i].ProductList.length; j++) {
            //if (result.SupplierProductList[i].ProductList[j].PriceUSD!=null) {
            //}
            html += "<tr><td>" + result.SupplierProductList[i].ProductList[j].Model + "</td><td>" + result.SupplierProductList[i].ProductList[j].Manufacturer + "</td><td>" + (result.SupplierProductList[i].ProductList[j].Quantity) + "</td><td>" + result.SupplierProductList[i].ProductList[j].ShipDays + "</td><td>" + result.SupplierProductList[i].ProductList[j].MinOrderQuantity + "+</td><td>" + result.SupplierProductList[i].ProductList[i].DeliveryPoint + "</td><td>" + result.SupplierProductList[i].ProductList[j].PriceUSD + "</td><td>" + result.SupplierProductList[i].ProductList[j].PriceCNY + "</td><td><a href=''>加入购物车</td></tr><br/>";
          }
        }
        //展示搜索--品牌列表
        var html2 = "<h2 class='cur1'>全部</h2>";
        if (result.ManufacturerList.length > 0) {
          for (var i = 0; i < result.ManufacturerList.length ; i++) {
            if (result.ManufacturerList[i].KeyName != null) {
              if (i < 5) {
                html2 += "<h2 href='javascript:void(0);' id='" + result.ManufacturerList[i].KeyName + "' onclick='Trademark(this)' >" + result.ManufacturerList[i].KeyName + "</h2>";
              }
            }
          }
          //<a href="javascript:void(0);" id="regain_r2">收回</a>
          html2 += "<a href='javascript:void(0);' id='more_r2' onclick='More_r2()'>更多+</a>";
        }
        //不删除第一个内容,将产品信息表追加
        $("#r2_text2").not($(".cur1")).empty();
        $("#r2_text2").append(html2);
        //改写品牌行
        $(".tr3").empty();
        $(".tr3").append(html);
      }
    }
  };
  $.ajaxRequest(PostExecParam);
};

Model:

如上这篇怎样选取AJAX完成按需加载【推荐】即是小编分享给大家的全部内容了,希望能给我们2个参照,也盼望我们多多援救脚本之家。

效用演示

.cshtml

namespace MvcApplication1.Models
{
 public class Team
 {
  public string Preletter { get; set; }
  public string Name { get; set; }
 }
}

你恐怕感兴趣的篇章:

  • ajax异步加载图片实例分析
  • 【皇家赌场手机版】Helper或Jquery异步加载部分视图,ajax完结产品页面加载音信。JQuery完毕Ajax加载图片的格局
  • 依照ajax实现点击加载越多无刷新载入到本页
  • js ajax加载时的进程条代码
  • javascript+ajax完成产品页面加载消息
  • jQuery+AJAX实现无刷新下拉加载越多
  • jQuery结合AJAX之在页面滚动时从服务器加载数据
  • jQuery结合ajax达成动态加载文本内容
  • Ajax加载外部页面弹出层效果落真实意况势
  • php+ajax+jquery完毕点击加载越来越多内容
  • php+ajax完毕无刷新动态加载数据能力
  • 【皇家赌场手机版】Helper或Jquery异步加载部分视图,ajax完结产品页面加载音信。jquery
    ajax局地加载方法详解(完结代码)

本例是分页的此外一种展现格局,并不是隐藏未显示的内容

<div class="secect_r">
    <div class="top_right">
      <ul>
        <li class="list1"><img src="~/MvcImages/ycysqd/sx_03.gif" /><p>筛选</p></li>
        <li class="list2"><a href="">集成电路</a>>></li>
        @*<li class="list3"><a>INFINEON</a>×</li>
        <li class="list3"><a>100-1000件</a>×</li>
        <li class="list3"><a>国内</a>×</li>*@
      </ul>
      <div class="r1"><h1>型号:</h1><div class="text1"><input id="typeofproduct" type="text" value="输入型号" /></div></div>
      <div class="r2"><h1>品牌:</h1><div class="text2" id="r2_text2"><h2 class="cur1">全部</h2><h2>FTDI</h2><h2>WIINET</h2><h2>3M-STATIC CONTROL SOLUTIONS</h2><h2>AAVID THERMALLOY</h2><h2>ALLIANCE</h2><a href="javascript:void(0);" id="more_r2" onclick="More_r2()">更多+</a></div><div class="text2" id="r2_text2_2" style="display:none"></div></div>
      <div class="r3"><h1>库存数量:</h1><div class="text1"><input type="text" class="ChangeInventoryquantity" id="startnumber" value="1000" /></div><a>-</a><div class="text2"><input class="ChangeInventoryquantity" id="endnumber" type="text" value="1000000" /></div><a>件</a></div>
      <div class="r4"><h1>交货地:</h1><div class="text2"><h2 class="cur1">全部</h2><h2 onclick="Trademark(this)">国内</h2><h2 onclick="Trademark(this)">香港</h2></div></div>
    </div>

  </div>
  <table class="bottom_right">
    <tr class="tr1">
      <td class="td1"><p>型号</p></td>
      <td class="td2"><p>品牌</p></td>
      <td class="td3"><p>库存数量</p></td>
      <td class="td4"><p>货期</p></td>
      <td class="td5"><p>起订量</p></td>
      <td class="td6"><p>交货地</p></td>
      <td class="td7"><p>香港交货</p></td>
      <td class="td8"><p>国内交货</p></td>
      <td class="td9"><p>操作</p></td>
    </tr>
    <tr class="tr2">
      <td></td>
      <td></td>
      <td></td>
      <td><p>(工作日)</p></td>
      <td></td>
      <td></td>
      <td></td>
      <td><p>(含17%税)</p></td>
      <td></td>
    </tr>

    <tbody class="tr3"></tbody>

  </table>

透过jQuery异步加载部分视图

数据库结构与《ajax 翻页》是千篇一律的

上述所述正是本文的全部内容了,希望大家能够喜欢。

Home/Index.cshtml视图中:

JavaScript 代码

你大概感兴趣的作品:

  • 如何行使AJAX完成按需加载【推荐】
  • ajax异步加载图片实例深入分析
  • JQuery实现Ajax加载图片的艺术
  • 听他们讲ajax完结点击加载更加多无刷新载入到本页
  • js ajax加载时的进程条代码
  • jQuery+AJAX完结无刷新下拉加载越来越多
  • jQuery结合AJAX之在页面滚动时从服务器加载数据
  • jQuery结合ajax实现动态加载文本内容
  • Ajax加载外部页面弹出层效果完毕格局
  • php+ajax+jquery落成点击加载越来越多内容
  • php+ajax达成无刷新动态加载数据手艺
  • jquery
    ajax局部加载方法详解(达成代码)
@{
 ViewBag.Title = "Index";
 Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<div>
 <a href="#" id="a">通过jQuery异步</a> <br/>
</div>
<div id="result">
</div>
@section scripts
{
 <script type="text/javascript">
  $(function() {
   $('#a').click(function() {
    $.ajax({
     url: '@Url.Action("Index","Home")',
     data: { pre: 'B' },
     type: 'POST',
     success: function(data) {
      $('#result').empty().append(data);
     }
    });
    return false;
   });
  });
 </script>
}
<script type="text/javascript"> 
$(document).ready(function() { 
  var track_click = ; //track user click on "load more" button, righ now it is click 
  var total_pages = <?php echo $total_pages; ?>; 
  $('#results').load("fetch_pages.php", {'page':track_click}, function() {track_click++;}); //initial data to load 
  $(".load_more").click(function (e) { //user clicks on button 
    $(this).hide(); //hide load more button on click 
    $('.animation_image').show(); //show loading image 
    if(track_click <= total_pages) //make sure user clicks are still less than total pages 
    { 
      //post page number and load returned data into result element 
      $.post('fetch_pages.php',{'page': track_click}, function(data) { 
        $(".load_more").show(); //bring back load more button 
        $("#results").append(data); //append data received from server 
        //scroll page to button element 
        $("html, body").animate({scrollTop: $("#load_more_button").offset().top}, ); 
        //hide loading image 
        $('.animation_image').hide(); //hide loading image once data is received 
        track_click++; //user click increment on load button 
      }).fail(function(xhr, ajaxOptions, thrownError) {  
        alert(thrownError); //alert any HTTP error 
        $(".load_more").show(); //bring back load more button 
        $('.animation_image').hide(); //hide loading image once data is received 
      }); 
      if(track_click >= total_pages-) 
      { 
        //reached end of the page yet? disable load button 
        $(".load_more").attr("disabled", "disabled"); 
      } 
     } 
    }); 
}); 
</script>

HomeController调节器中:

XML/HTML代码

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
 public class HomeController : Controller
 {
  public ActionResult Index()
  {
   return View();
  }
  [HttpPost]
  public ActionResult Index(string pre)
  {
   var result = GetAllTeams().Where(t => t.Preletter == pre).ToList();
   ViewBag.msg = "通过jQuery异步方式到达这里~~";
   return PartialView("TeamY", result);
  }
  private List<Team> GetAllTeams()
  {
   return new List<Team>()
   {
    new Team(){Name = "巴西队", Preletter = "B"},
    new Team(){Name = "克罗地亚队", Preletter = "K"},
    new Team(){Name = "巴拉圭", Preletter = "B"},
    new Team(){Name = "韩国", Preletter = "K"}
   };
  }
 }
}
<div id="results"></div> 
<div align="center"> 
<button class="load_more" id="load_more_button">load More</button> 
<div class="animation_image" style="display:none;"><img src="ajax-loader.gif"> Loading...</div> 
</div> 

有的视图TeamY.cshtml:

 fetch_pages.php

@model IEnumerable<MvcApplication1.Models.Team> 
@{
 var result = string.Empty;
 foreach (var item in Model)
 {
  result += item.Name + ",";
 }
}
@ViewBag.msg.ToString()
<br/>
@result.Substring(0,result.Length - 1)

 php代码

经过MVC Ajax Helper异步加载部分视图

<?php 
include("conn.php"); 
$item_per_page = 3; 
//sanitize post value 
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); 

//throw HTTP error if page number is not valid 
if(!is_numeric($page_number)){ 
  header('HTTP/1.1 500 Invalid page number!'); 
  exit(); 
} 

//get current starting point of records 
$position = ($page_number * $item_per_page); 

//Limit our results within a specified range.  
$results = mysql_query("SELECT * FROM content ORDER BY id DESC LIMIT $position, $item_per_page"); 

//output results from database 
echo '<ul class="page_result">'; 
while($row = mysql_fetch_array($results)) 
{ 
  echo '<li id="item_'.$row["id"].'">'.$row["id"].') '.$row["name"].''.$row["message"].'</li>'; 
} 
echo '</ul>'; 
?> 

Home/Index.cshtml视图中须求引用jquery.unobtrusive-ajax.js文件,从调节器重回的强类型部分视图内容展现到UpdateTargetId内定的div中。

如上内容是作者给我们介绍的根据ajax达成点击加载越多无刷新载入到本页,希望大家脍炙人口。

@{
 ViewBag.Title = "Index";
 Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<div>
 @Ajax.ActionLink("通过MVC Ajax Helper","Load","Home", new {pre = "K"}, new AjaxOptions(){UpdateTargetId = "result1"})
</div>
<div id="result1">
</div>

您恐怕感兴趣的篇章:

  • 什么运用AJAX完毕按需加载【推荐】
  • ajax异步加载图片实例解析
  • JQuery达成Ajax加载图片的格局
  • js ajax加载时的进度条代码
  • javascript+ajax实现产品页面加载音讯
  • jQuery+AJAX达成无刷新下拉加载越来越多
  • jQuery结合AJAX之在页面滚动时从服务器加载数据
  • jQuery结合ajax达成动态加载文本内容
  • Ajax加载外部页面弹出层效果完结格局
  • php+ajax+jquery完毕点击加载更加多内容
  • php+ajax完成无刷新动态加载数据本事
  • jquery
    ajax局地加载方法详解(完成代码)

HomeController调控器中:

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
 public class HomeController : Controller
 {
  public ActionResult Index()
  {
   return View();
  }
  public ActionResult Load(string pre)
  {
   var result = GetAllTeams().Where(t => t.Preletter == pre).ToList();
   ViewBag.msg = "通过MVC Ajax Helper到达这里~~";
   return PartialView("TeamY", result);
  }
  private List<Team> GetAllTeams()
  {
   return new List<Team>()
   {
    new Team(){Name = "巴西队", Preletter = "B"},
    new Team(){Name = "克罗地亚队", Preletter = "K"},
    new Team(){Name = "巴拉圭", Preletter = "B"},
    new Team(){Name = "韩国", Preletter = "K"}
   };
  }
 }
}

1部分视图和上1种艺术一样。

页面刷新的办法加载部分视图方法包蕴:

Html.RenderPartial()
Html.RenderAction()

上边给大家介绍MVC中贯彻部分内容异步加载

action中定义1个收获结果集的办法

public ActionResult GetItemTree(string title, int itemid, int? page)
  {
   pp = new PagingParam(page ?? 1, VConfig.WebConstConfig.PageSize);
   Common.Page.PagedList<Entity.Res_Item_Resource_R> res_Item_Resource_R = iResourceService.GetRes_Item_Resource_RByItemId(itemid, pp);
   ViewData["res_Item_Resource_R"] = res_Item_Resource_R;
   res_Item_Resource_R.AddParameters = new System.Collections.Specialized.NameValueCollection();
   res_Item_Resource_R.AddParameters.Add("title", title);
   res_Item_Resource_R.AddParameters.Add("itemid", itemid.ToString());

   ViewResult vr = new ViewResult
   {
    ViewData = ViewData,
    MasterName = "",
   };
   return vr;
  }

    在主页面使用上边jquery代码异步调用下边的action

 $(function () {
  var id = '<%=itemid %>';
  $.ajax({
   type: "POST",
   url: "/Student/GetItemTree",
   data: { title: '<%=Model.Name %>', itemid: id, page: 1 },
   beforeSend: function (data) { //取回数据前
    $("#itemTree").html('数据加载中...');
   },
   error: function (data) { //发生错误时
//    debugger;
   },
   success: function (data) { //成功返回时
    $("#itemTree").html(data);
   }
  });

   最终在分局视图GetItemTree.ascx中写上您要赶回的数据结构就能够
   注意一点便是,如若涉及到分页,要用AJAX分页方式

<div style="float: left">
  <%=Html.AjaxPager(resItemResourceBefore, "itemTree", "GetItemTree", "Student")%>
 </div>

你只怕感兴趣的小说:

  • jQuery Ajax
    加载数据时异步展现加载动画
  • jQuery Ajax
    异步加载呈现等待效果代码分享
  • ajax异步加载图片实例解析
  • 用ajax动态加载必要的js文件
  • 皇家赌场手机版,jQuery+AJAX完毕无刷新下拉加载更加的多
  • jQuery 瀑布流
    浮动布局(壹)(延迟AJAX加载图片)
  • php+ajax+jquery完结点击加载更加多内容
  • Jquery仿Taobao京东多规格筛选可自动结合ajax加载示例
  • php+ajax完毕无刷新动态加载数据技能
  • Ajax 异步加载分析

Leave a Comment.