您现在的位置是:

jquery中使用ajax跨域请求及分页

发布时间:2019-09-25作者:小灵龙来源:未知点击:137

问题描述:

  在自己的网站上使用ajax调用其他网站的数据。

解决办法:
第一种办法:

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>商标注册</title>


<script type="text/javascript" src="static/js/jquery-1.7.1.js"></script>



    <script type="text/javascript">

        //当前页码

        var currentPage = 1;

        $(function () {

            //InitTable();

            $("#domaininfo").keypress(function (e) { //这里给function一个事件参数命名为e,叫event也行,随意的,e就是IE窗口发生的事件。

                var key = e.which; //e.which是按键的值

                if (key == 13) {

                    searchData();
                }
            });

        });

        function InitTable() {

            var zch;

            var sbname;

            var sqr;

            var sstype = $("#sstype").val();  //1商标名 2注册号 3 申请人
            var strwhere = $.trim($("#domaininfo").val());

            if (strwhere == "" || strwhere == null)

            {

                return false;
            }

            if (sstype == 1)

            {

               sbname = strwhere;

            } else if (sstype == 2) {

                if (strwhere != "" && !CndnsValidate.checkNumber(strwhere)) {

                    alert("注册号输入错误,只能是数字");

                    return false;

                } else {

                    zch = strwhere;

                }

            } else if (sstype == 3) {

                sqr = strwhere;

            }


            //var zcstate = $("#zcstate").val();  //注册状态查询 1已注册 2 审核中 3 已无效

            var zcstate = "";  //注册状态查询 1已注册 2 审核中 3 已无效

           

            //国际分类

            var checkgjfl="";

            $.each($(".brandSearch-typeBody li[class='btn-selected']"), function () {

                checkgjfl += $.trim( $(this).find("p").text()).substring(0, 2)+",";

            });

            if (checkgjfl.length > 0) {

                checkgjfl = checkgjfl.substring(0, checkgjfl.length - 1);

            }

           
            $.ajax({

                type: "POST",

                url: "https://www.cndns.com/Ajax/cy.ashx?module=GetSBlist_Index",

                data: { "currentPage": currentPage, "sbmc": sbname, "zch": zch, "sqr": sqr, "pageSize": 10, "sstype": sstype, "zcstate": zcstate, "gjfls": checkgjfl },

                dataType: "json",

                beforeSend: function (xhr) {

                    $('.brandSearch-listBody').html('<div class="loadingsb"><span></span><div>');

                    $('.brandSearch-list').show();

                },

                error: function (XMLHttpRequest, textStatus, errorThrown) {

                    $('.brandSearch-listBody').html('<div><span class="nodata">获取数据失败,请刷新重试!</span></div>');

                },

                success: function (result) {

                    console.log(result);

                    if (result != null) {

                   

                        if (result.status == "success") {



                            FormatHtml(result, currentPage);

                        } else {

                            var pageHtml = "<option value='1'>1</option>";

                            $('.brandSearch-listBody').html("<div class=\"nodata\"><p class=\"error-txt\">查询不到符合条件的商标</p><p class=\"timer\">您可以立即进行商标注册<a onclick=\"javascript:window.open('http://wpa.b.qq.com/cgi/wpa.php?ln=1&amp;key=XzgwMDAxNTU0Nl8zMzQwMDNfODAwMDE1NTQ2XzJf', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no');\">马上注册</a></p></div>");

                            $('#selectPage').html(pageHtml);

                            $('#currentPage').html(1);

                            $('#pageCount').html(1);

                            $("#sumCount").text(0);

                        }

                    } else {

                       

                    }

                }

            });

        }



        //格式化json,拼html

        function FormatHtml(result, currentPage) {

            var _html = '';

            var pageHtml = '';

            var tableData = result.message; //表格数据


            var currentPage = currentPage; //当前页码

          
            var pageCount = result.pageCount; //总页数

           
            var AllCounts = result.AllCounts; //总条数

           // var pageCount = AllCount/20; //总页码

            for (var i = 0; i < tableData.length; i++) {

                var sbmc=tableData[i].sbmc;  //商标名称

                var zch=tableData[i].zch;

                var sqrq=tableData[i].sqrq;

                var zcrzwname=tableData[i].zcrzwname;

         

                var csggqh=tableData[i].csggqh;

                var csggrq=tableData[i].csggrq;

                var zcggrq=tableData[i].zcggrq;

 

                var gjfl=tableData[i].gjfl;

                var lsq = tableData[i].lsqidstrs;

               

                var myDate = new Date();

                var ntime= myDate.toLocaleDateString()

                var state=0;

                if (csggqh != "" && csggqh!=null)

                {

                    state = 1;

                }

                else if (csggqh == "" || csggqh == null)

                {

                    state = 3;

                }

                else if (zyqjsrq < ntime)

                {

                    state = 2;                

                }

                

                if (lsq==null) {

                    lsq = "";

                }

               // var state = tableData[i].zcstate; //注册状态



                var shouimg;

                var img = "http://pic.www2.cndns.com/sbico/" + zch + ".jpg";

                var imgstr = "";



                _html += '<ul><li><a href="/cn/51cy/sbDetail.aspx?zch=' + zch + '" class="clearfix" target="_blank">';

                _html += "<div class='fl liImg'><img src='static/picture/5aacfcfec9bb439a857d690583f428de.gif" + zch + ".jpg' alt='" + sbmc + "' onerror=\"javascript:this.src='https://www.cndns.com/cn/51cy/images/zz.jpg'; this.onerror=null; \" /></div>";

                _html += '<div class="fr liBody">';

                _html += '<div class="liBody-top clearfix">';

                _html += '<div class="fl">';

                _html += '<h5>' + sbmc + '</h5>';

                _html += '<h5><span class="info-additional">第' + gjfl + '类-' + fnGetType(gjfl) + '<span>|</span>注册号:' + zch + '</span></h5>';

                _html += '</div>';

                _html += '<div class="fr">';

                var color = "";

                if (state=="1") {

                    color = "style='background-color:#00FFFF;'";

                } else if (state == "3") {

                    color = "style='background-color:red;'";

                }

                _html += '<span class="status-valid" ' + color + '>' + fnState(state) + '</span>';

                _html += '</div>';

                _html += '</div>';

                _html += '<div class="liBody-bot clearfix">';

                _html += '<div class="liBody-text liBody-textA">';

                _html += '<p class="clearfix"><span class="spanA">商品服务</span><span class="spanB">' + lsq + '</span></p>';

                _html += '</div>';

                _html += '<div class="liBody-text">';

                _html += '<p><span class="spanA">初审公告期号:</span><span class="spanB">' + csggqh + '</span></p>';

                _html += '<p><span class="spanA">初审公告日期:</span><span class="spanB">' + csggrq + '</span></p>';

                _html += '<p><span class="spanA">注册公告日期:</span><span class="spanB">' + zcggrq + '</span></p>';

                _html += '</div>';

                _html += '<div class="liBody-text">';

                _html += '<p><span class="spanA">申请人:</span><span class="spanB">' + zcrzwname + '</span></p>';

                _html += '<p><span class="spanA">申请日期:</span><span class="spanB">' + sqrq + '</span></p>';

                _html += '</div>';

                _html += '</div>';

                _html += '</div>';

                _html += '</a>';

                _html += '</li></ul>';


            }



            $("#sumCount").text(AllCounts);



            for (var i = 1; i < Number(pageCount) + 1; i++) {

                pageHtml += "<option value='" + i + "'>" + i + "</option>";

            }



            if (pageCount == 1) {

                $('#upPage').unbind().css("cursor", "not-allowed");

                $('#downPage').unbind().css("cursor", "not-allowed");

            } else if (currentPage == 1) {

                $('#upPage').unbind().css("cursor", "not-allowed");

                $('#downPage').unbind().bind('click', function () {

                    ChangePage(currentPage + 1);

                }).css("cursor", "pointer");

            }else if (currentPage == pageCount) {

                $('#upPage').unbind().bind('click', function () {

                    ChangePage(currentPage - 1);

                }).css("cursor", "pointer");

                $('#downPage').unbind().css("cursor", "not-allowed");

            } else {

                $('#upPage').unbind().bind('click', function () {

                    ChangePage(currentPage - 1);

                }).css("cursor", "pointer");

                $('#downPage').unbind().bind('click', function () {

                    ChangePage(currentPage + 1);

                }).css("cursor", "pointer");

            }



            $('.brandSearch-listBody').html(_html);

            $('#selectPage').html(pageHtml);

          

            $('#currentPage').html(currentPage);

            $('#pageCount').html(pageCount);

            $("#selectPage").attr("value", currentPage);

        }



        //翻页事件

        function ChangePage(page) {

          

            currentPage = page;

            InitTable();

        }



        //搜索重载表格数据

        function searchData() {

           

            currentPage = 1;

            InitTable();

        }



        function fnState(state) {

            if (state == 1)

            {

                return "已注册";

            } else if (state == 2)

            {

                return "审核中";

            } else if (state == 3)

            {

                return "已无效";

            }

        }



        function fnGetType(number) {

            if (number == 1) {

                return "化学原料";

            } else if (number == 2) {

                return "颜料油漆";

            } else if (number == 3) {

                return "日化用品";

            } else if (number == 4) {

                return "燃料油脂";

            } else if (number == 5) {

                return "医药";

            } else if (number == 6) {

                return "金属材料";

            } else if (number == 7) {

                return "机械设备";
            }
        }

        function CheckImgExists(imgurl) {

            var ImgObj = new Image(); //判断图片是否存在  

            ImgObj.src = imgurl;

            //没有图片,则返回-1  

            if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {

                return true;

            } else {

                return false;

            }



        }



        function refreshVcodes() {

           

            var src = '/common/GenerateCheckCode.aspx?t=sign&temp=' + Math.random();

            $(".VcodeImg").attr("src", src);

        }


        //域名查询

        function loadSearchDomain() {

            var domainInfo = $("#domainInfo").val();

            var suffix = ".商标";

            if (domainInfo == "")

            {

                alert("请输入域名!");

                return;

            }

            send("domain", domainInfo, suffix);

        }



        //发送到服务器上查询

        function send(panel, name, suffix) {

            var usrcls = $("#usrcls").val();

            var usrname = $("#usrname").val();

            var cookieid = $("#cookieid").val();

            var batch = $("#batch").val();

            var sbtype = $("#shangbiaoType").val();

            

            var esname = escape(name);



            var domainquerysign = "";



            var param = "panel=" + panel + "&domainName=" + esname + "&domainSuffix=" + escape(suffix) + "&usrcls=" + usrcls + "&cookieid=" + cookieid + "&usrname=" + usrname + "&sbtype=" + sbtype;



            var signname = $("#" + name + "sign");

            if (signname.size() <= 0) {

                $("#searchparam").prepend("<input type='hidden' id='" + name + "sign' value=''>");

                $.get("https://www.cndns.com/cn/Ajax/buildkey.ashx?module=getkey&domainName=" + esname, function (data) {

                    if (data != "") {

                        $("#searchparam").find("#" + name + "sign").val(data);



                        param = param + "&domainquerysign=" + data;



                        domainQuery(param);



                    }

                });

            } else {

                if (signname.val() != "") {

                    domainquerysign = signname.val();

                    param = param + "&domainquerysign=" + domainquerysign;

                    domainQuery(param);

                } else {

                    setTimeout("send('" + panel + "','" + name + "','" + suffix + "')", 500);

                }

            }



        }



        function domainQuery(param) {

            $.get("https://www.cndns.com/cn/Ajax/domainQuery.ashx?" + param, function (data) {

                var values = data.split("|");

                if (values.length > 0) {

                    var domainstatus = values[0];

                    var idname = values[1];

                    var domainname = values[2];

                    var domainsuffix = values[3];

                    var domainprice = values[4];

                    var domainprd = values[5];

                    var panel = values[6];

                    var token = "";

                    var ortejia = "";

                    if (values.length > 7) {

                        token = values[8];

                    }

                    if (values.length > 8) {

                        ortejia = values[9];

                    }



                    receive(panel, idname, domainstatus, domainname, domainsuffix, domainprice, domainprd, token, ortejia);

                }

            });

        }



        //显示查询结果

        function receive(panel, idname, domainstatus, domainname, domainsuffix, domainprice, domainprd, token, ortejia) {

            var html = "";

            var domainList = $("#domainList");

            var weizhucedomainList = $("#weizhucedomainList");

            var yizhucedomainList = $("#yizhucedomainList");

            var queryerrordomainList = $("#queryerrordomainList");

            var obj = $("#" + idname);

            $("#showResult").show();

            if (domainstatus == "10000" || domainstatus == "10003" || domainstatus == "10004") {

                $("#domainname").html(domainname);

                $("#iszhuce").html("可以注册");

                //if (obj.size() > 0) {

                  

                //} else {

                //    weizhucedomainList.append(html);

                //}

               

            } else  {

                $("#domainname").html(domainname);

                $("#iszhuce").html("不可以注册");

            }



        }

      
    </script>


</head>

<body>


    <div class="brand_main">

      <div class="brand_main_o">

        <div class="w-1200">

         

          <div class="clear"></div>



               <div class="brandSearch">

              <div class="brandSearch-body">

                  <div class="brandSearch-con fl">

                      <select id="sstype">

                          <option value="1">商标名</option>

                          <option value="2">注册号</option>

                          <option value="3">申请人</option>

                          

                      </select>

                      <input type="text" id="domaininfo"  placeholder="输入您想要搜索的名称" />

                  </div>

                  <div class="brandSearch-btn fr">

                      <a href="javascript:(0)"  onclick="searchData()">查商标</a>

                  </div>

                  <div class="clear"></div>

              </div>

              

                  

            <div class="brandSearch-list brandSearch-box" style="display:none;">

                <div class="brandSearch-listHead brandSearch-listBox clearfix" >

                    <div class="fl page-box">

                        <div class="pagination-goto">

                            

                            <p class="pagination-info">(商标检索结果仅供参考,不作为商标能否注册的法律依据;具体以<a href="http://sbj.sc.gov.cn/sbcx/?spm=5176.212713.1131432.2.106f135at7xLME" target="_blank" name="start" id="start" >商标局官网</a>查询为准。)</p>

                        </div>

                    </div>

                    <div class="fr page-box">

                        <p class="pagination-info">共有<span id="sumCount"></span>个搜索结果</p>

                    </div>

                </div>

                <div class="brandSearch-listBody">

                    

                </div>

                <div class="brandSearch-listFoot brandSearch-listBox clearfix">

                    <div class="fr page-box">

                        <p class="pagination-info"><label id="currentPage">1</label>/<span class="col-1" id="pageCount">1</span>页</p>

                        <div class="pagination"><a href="#start" class="btn btn-default" id="upPage">上一页</a><a href="#start" class="btn btn-default" id="downPage">下一页</a></div>

                        <div class="pagination-goto"><span>跳转</span><select id="selectPage" onchange="ChangePage($('#selectPage').val())"><option>1</option></select><span>页</span></div>

                    </div>

                </div>

            </div>

          </div>

        </div>

      </div>


    </div>
 
</body>

</html>

第二种办法:


<!DOCTYPE html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<script src="static/js/jquery-1.7.1.js" type="text/javascript"></script>

</head>

<body>


<!-- /header -->

<!-- main -->



<div class="price clearfix">



<div class="bk30"></div>



       <div class="publicinfo-box">

<div class="large-search-box">


    <div class="large-search-con">


        <input name="key" type="text" id="key" class="input-large-search" placeholder="请输入关键字" value="">

            <input type="button" name="button" id="searchbutton" value="搜 索" class="btn-large-search">


        <div class="clear"></div>


    </div>

</div>


<div class="search-condition">



    <ul>



        <li class="clearfix" id="mtdl">



            <div class="text-block">



                <div class="list-left">媒体小类:</div>

                <div class="list-right">

                    <div class="beginning"><a href="javascript:;" class="active" data="-1">不限</a></div>

                    <div class="text-block">

                        <p id="mtdl_load">

                                                        <a href='javascript:;' data='30'>工业贸易</a>

                                                          <a href='javascript:;' data='31'>生活消费</a>

                                                          <a href='javascript:;' data='32'>女性时尚</a>

                                                          <a href='javascript:;' data='33'>娱乐休闲</a>

                                                          <a href='javascript:;' data='34'>游戏网站</a>

                                                          <a href='javascript:;' data='35'>汽车网站</a>

                                                          <a href='javascript:;' data='36'>教育培训</a>

                                                       
                        </p>
                    </div>
                </div>
            </div>
        </li>


        <li class="clearfix" id="mtxl">


            <div class="text-block">


                <div class="list-left">五大门户:</div>


                <div class="list-right">


                    <div class="beginning"><a href="javascript:;" class="active"  data="-1">不限</a></div>


                    <div class="text-block">

                        <p id="pdlx_load">
                           

                            <a href='javascript:;' data='50'>凤凰网</a>

                      
                            <a href='javascript:;' data='49'>新浪网</a>


                            <a href='javascript:;' data='48'>腾讯网</a>


                            <a href='javascript:;' data='47'>搜狐网</a>


                            <a href='javascript:;' data='46'>网易网</a>


                        </p>

                    </div>

                </div>

            </div>

        </li>

        <li class="clearfix" id="mtjg">

            <div class="list-left">价格分类媒体:</div>

            <div class="list-right">


                <div class="beginning"><a href="javascript:;" class="active" data="-1" >不限</a></div>


                <div class="text-block">

                    <p>

                      <a href='javascript:;' data="0">0-40元</a>


                      <a href='javascript:;' data="1">40-70元</a>


                      <a href='javascript:;' data="2">70-120元</a>

                      <a href='javascript:;' data="3">120元以上</a>

                    </p>

                </div>
            </div>
        </li>

        <li class="clearfix" id='mtdq'>

            <div class="list-left">地区分类媒体:</div>

            <div class="list-right">

                <div class="beginning"><a href="javascript:;" class="active" data="-1" >不限</a></div>

                <div class="text-block"><p>

                        <a href="javascript:;" data="全国">全国</a>

                        <a href="javascript:;" data="北京">北京</a>


                        <a href="javascript:;" data="上海">上海</a>


                        <a href="javascript:;" data="广东">广东</a>


                        <a href="javascript:;" data="浙江">浙江</a>

                        <a href="javascript:;" data="天津">天津</a>

                  
                        <a href="javascript:;" data="重庆">重庆</a>



                </p></div>

                </div>

        </li>
    </ul>

</div>

</div>


<!--publicinfo-box end-->



       <div class="publicinfo-box">

            <div class="sequence">


            <div class="sequence-list floatRight" id="paixu" style="float:left">


                <a href="javascript:;" onClick="" class="active" data="0"><span>默认排序</span><i class="icon-sequence-up"></i></a>


                <a href="javascript:;" onClick=""  data="1"><span>按价格升序</span><i class="icon-sequence-up"></i></a>


                    <a href="javascript:;" onClick=""  data="2"><span>按价格降序</span><i class="icon-sequence-up"></i></a>


                      <a href="javascript:;" onClick=""  data="3"><span>按推荐排序</span><i class="icon-sequence-up"></i></a>


                    </div>


                    <h2 class="floatLeft" style="float:right;margin-right:10px;">为您搜索到 <strong id='totalnum'></strong> 条网站资源</h2>


            <div class="clear"></div>

        </div>


    <!--paixu end-->

    <div class="tablebox" id="result">

        <table class="billing-table" width="100%" cellspacing="0" cellpadding="0" border="0">

          <thead>

            <tr>

              <td width="100">媒体分类</td>

              <td width="150">媒体名称</td>

              <td width="65">推荐指数</td>

              <th width="100"><div align="center"><strong>代理价</strong></div></th>

            <th width="100"><div align="center"><strong>零售价</strong></div></th>

              <td width="75">带网址情况</td>

              <td width="65">新闻源</td>

              <td width="80">备注</td>

            </tr>

              </thead>

              <tbody id="content">
            </tbody>

          
        </table>

        <div class="brandSearch-listFoot brandSearch-listBox clearfix">

                    <div class="fr page-box">

                        <p class="pagination-info" style="float: left;margin-top: 7px;margin-right: 10px;">

                            <label id="currentPage">1</label>/<span class="col-1" id="pageCount">1</span>页

                        </p>



                        <div class="pagination" style="float: left;margin-right: 10px;">

                            <a href="#start" class="btn btn-default" id="upPage">上一页</a>

                            <a href="#start" class="btn btn-default" id="downPage">下一页</a>

                        </div>



                        <div class="pagination-goto" style="float: left;margin-top: 6px;">

                            <span>跳转</span>



                            <select id="selectPage" onchange="ChangePage($('#selectPage').val())">

                                <option>1</option>

                            </select>



                            <span>页</span>

                        </div>

                    </div>

                </div>

    </div>

    <!--tablebox end-->

    <div class="clear"></div>



</div>



<!--public-box end-->

<div class="clear"></div>


</div>

<!--contentbox end-->

</div>

</div>

<!-- /main -->

<div class="footer com_bg">

  <!--row_08 end-->
 
</div>

    <script type="text/javascript">

    var currentPage=1;

         searchMedia();

         //搜索关键词

         $(".btn-large-search").click(function(){
            searchMedia();

        })

        $("#mtdl a").click(function(){

            $("#mtdl a.active").removeClass("active");

            $(this).addClass("active");

            searchMedia();
        })

        $("#mtxl a").click(function(){



            $("#mtxl a.active").removeClass("active");

            $(this).addClass("active");

            searchMedia();

        })


        $("#mtjg a").click(function(){


            $("#mtjg a.active").removeClass("active");

            $(this).addClass("active");
            searchMedia();

        })

        $("#mtdq a").click(function(){

            $("#mtdq a.active").removeClass("active");

            $(this).addClass("active");

            searchMedia();

        })

        $("#paixu a").click(function(){

            $("#paixu a.active").removeClass("active");

            $(this).addClass("active");

            searchMedia();

        })


        function searchMedia(){

            //搜索关键词

            if($(".input-large-search").val().length > 0)

            {
                searchtext =  $(".input-large-search").val();

            }else {

                searchtext='';

            }

            //媒体小类

            if($("#mtdl a.active").attr("data") != "-1")

            {

                fl =  $("#mtdl a.active").attr("data");


            }else {

                fl='';

            }

           

            //五大门户

            if($("#mtxl a.active").attr("data") != "-1")


            {


                fls = $("#mtxl a.active").attr("data");


            }else {

                fls='';

            }


            //媒体价格

            if($("#mtjg a.active").attr("data") != "-1")

            {

                jg =  $("#mtjg a.active").attr("data");

            }else {

                jg='';

            }

            //媒体地区

            if($("#mtdq a.active").attr("data") != "-1")

            {

                dq =$("#mtdq a.active").attr("data");

            }else {

                dq='';

            }

            //排序

        if($("#paixu a.active").attr("data") != "-1")

        {

            ordertype = $("#paixu a.active").attr("data");

        }

            $.ajax({

                type: "post",

                data: {"fl":fl,"fls":fls,"jg":jg,"dq":dq,"ordertype":ordertype,"searchtext":searchtext,"currentpage":currentPage},

                url: "http://rw.itulan.com/vip/callback.php",

                dataType: "json",

                success: function(data) {

                    console.log(data);

                    if(data.data != null){

                        if(data.success==true){

                             FormatHtml(data,currentPage);

                        }else {

                        }

                    }else {

                         $('#content').html("");

                         $('#selectPage').html(pageHtml);

                            $('#currentPage').html(1);

                            $('#pageCount').html(1);

                          $("#totalnum").text(0);


                    }
 

                },

                error: function() {

                  console.log('Request Error.');

                }

            });

            //格式化json,拼html

            function FormatHtml(data,currentpage){

                var _html = '';

                var tableData = data.data; //表格数据



                var pageHtml='';

                var currentpage=currentpage;//当前页码

                var AllCounts=data.AllCounts;//数据总条数

                var pageCount = data.pageCount; //总页数

               

                for (var i = 0; i < tableData.length; i++) {

                    var id=tableData[i].id; 

                    var nav_id=tableData[i].nav_id;

                    var class_id=tableData[i].class_id;

                    var tj=tableData[i].tj.replace('..','/static');

            

                    var medianame=tableData[i].medianame;

                    var anliurl=tableData[i].anliurl;

                    var xinwenyuan=tableData[i].xinwenyuan;

                    if(tableData[i].linkurl==null){

                        var linkurl='';

                    }else {

                        var linkurl=tableData[i].linkurl;

                    }

                    var smallclass=tableData[i].classid;

     

                    var diqu=tableData[i].diqu;

                    var price = tableData[i].price;

                    var dlprice = tableData[i].dlprice;

                    var content = tableData[i].content;

                  

                    _html += '<tr>';

                    _html += '<td>' + medianame + '</td>';

                    _html += '<td>' + medianame + '</td>';

                    _html += '<td> <img src="' + tj + '" ></td>';

                    _html += '<td><a href="http://wpa.qq.com/msgrd?v=3&uin=995637708&site=qq&menu=yes">查询</a></td>';

                    _html += '<td><a href="http://wpa.qq.com/msgrd?v=3&uin=995637708&site=qq&menu=yes">查询</a></td>';

                    _html += '<td>' + linkurl + '</td>';

                    _html += '<td>' + xinwenyuan + '</td>';

                    _html += '<td>' + content + '</td>';

                  

                    _html += '</tr>';

                   

                }

                // 查询结果总条数显示

                $("#totalnum").text(AllCounts);

                for (var i = 1; i < Number(pageCount) + 1; i++) {

                pageHtml += "<option value='" + i + "'>" + i + "</option>";

            }



            if (pageCount == 1) {

                $('#upPage').unbind().css("cursor", "not-allowed");

                $('#downPage').unbind().css("cursor", "not-allowed");

            } else if (currentPage == 1) {

                $('#upPage').unbind().css("cursor", "not-allowed");

                $('#downPage').unbind().bind('click', function () {

                    ChangePage(currentPage + 1);

                }).css("cursor", "pointer");

            }else if (currentPage == pageCount) {

                $('#upPage').unbind().bind('click', function () {

                    ChangePage(currentPage - 1);

                }).css("cursor", "pointer");

                $('#downPage').unbind().css("cursor", "not-allowed");

            } else {

                $('#upPage').unbind().bind('click', function () {

                    ChangePage(currentPage - 1);

                }).css("cursor", "pointer");

                $('#downPage').unbind().bind('click', function () {

                    ChangePage(currentPage + 1);

                }).css("cursor", "pointer");

            }


            $('#selectPage').html(pageHtml);


            $('#currentPage').html(currentPage);

            $('#pageCount').html(pageCount);

            $("#selectPage").attr("value", currentPage);

                $('#content').html(_html);


            }

        }

        //翻页事件

            function ChangePage(page){

             
                currentPage=page;

                searchMedia();

            }

    </script>

</body>

</html>

php代码:
<?php

    header("Access-Control-Allow-Origin: http://sou.heijuke.com");

include ("../include/config.php");

include ("../include/function.php");


$sql = "select * from media_info where sh=1 and (nav_id=46 or nav_id=64) ";


//搜索关键词

if($_POST["searchtext"] <> ""){



    $parsearchtext = inject_check($_POST["searchtext"]);



    $sql .= " and medianame like '%".$parsearchtext."%'";

}


//媒体小类

if($_POST["fl"]<>""){

    $parfl=inject_check($_POST["fl"]);

    $sql .= " and class_id=".$parfl;


}


//五大门户(优惠类别)


if($_POST["fls"]<>""){

    $parfls=inject_check($_POST["fls"]);// 凤凰网 ID:50

    $sql .= " and small_id=".$parfls;

}

 //价格

if($_POST["jg"]<>""){



    $parjg=inject_check($_POST["jg"]);

    switch($parjg)

        {

         case "0":

           $sql .= " and (dlprice between 0 and 40)";

           break;

         case "1":

           $sql .= " and (dlprice between 41 and 70)";

           break;

         case "2":

           $sql .= " and (dlprice between 71 and 120)";

           break;

         case "3":

           $sql .= " and dlprice >120";

           break;

         default:

           $sql .= "";

        }

}


//地区

if($_POST["dq"]<>""){

    $pardq=inject_check($_POST["dq"]);

    $sql .= " and diqu='".$pardq."'";

}

//排序d

if($_POST["ordertype"]<>""){

    $skey=inject_check($_POST["ordertype"]);

    switch($skey)

    {

        case "0":

            $sql .= " order by dlprice asc";
            break;

        case "1":

            $sql .= " order by dlprice asc";

            break;

        case "2":

            $sql .= " order by dlprice desc";

            break;

        case "3":

            $sql .= " order by tj desc";

            break;

        case "4":

            $sql .= " order by fans desc";
            break;
        default:
            $sql .= " order by ID desc";

    }

}

//分页,查询的起始位置

if($_POST['currentpage'] !=""){

    $currentpage=$_POST['currentpage'];

}

//limit限定查询参数

$current=($currentpage-1) * 30;

//查询的总条数

$results=mysql_db_query($dbname,$sql);

$total='';

while($rsd=mysql_fetch_array($results))    {

    $total++;

}



//限定查询

$sql .=" limit ".$current.",30";

$result=mysql_db_query($dbname,$sql);

while($rs=mysql_fetch_array($result))

        {

            $arr[]=$rs;

        }

    if($arr==''){

        $data=array(

        "message"=>"失败",

        "data" => $arr,

        "success"=>false,

        "sql"=>$sql

        );

    }else {

        $data=array(

        "message"=>"成功",

        "data" => $arr,

        "pageCount"=>ceil($total/5),//总页数

        "AllCounts"=>$total,//总条数

        "success"=>true,

        "sql"=>$sql

        );

    }

   

echo json_encode($data);

如果帮到了您,请打赏一二!

标签:ajax跨域 jquery分页