ajax 请求另一个html页面的指定的一部分 加载到本页面div

ajax 请求另一个html页面的指定的一部分 加载到本页面div

$.ajax( {
        url: url, //这里是静态页的地址
        type: "GET", //静态页用get方法,否则服务器会抛出405错误
        success: function(data){
            var result = $(data).find("另一个html页面的指定的一部分");
            $("本页面div").html(result);

        }
});
例如:
<script type="text/javascript">
 
                      $.ajax({   
                      url: '/' + currentBlogApp + '/mvc/blog/Minyx2_Lite_SideColumn.aspx',
                      data:'{}',
                      type: 'post',
                      dataType: 'text',
                      contentType: 'application/json; charset=utf-8',
                      success: function (data){                           
                      if (data) {           
                      var zhi=$(data).find("h1");
                      $("#sideContainer").html(zhi);                             
                       }
                      }
                      });
                     </script>

转载:https://www.cnblogs.com/webqiand/p/4602717.html

--------------------------------------------------------------自己项目------------------------------------------------------------------------

当前页面servers.html 去获取 detail.html页面数据 

servers.html   
<tbody> <!--<?php dump($servers);?>--> <volist name="servers" id="item"> <tr id="90005" class=""> <!--<td align="center" class="type">--> <!--<a title="正式服务器" class="y" href="user_server.asp?type=1">正</a>--> <!--</td>--> <td>{$item.id}</td> <php>if (in_array('server_name',$list_fields_checked,true)) {</php> <td>{$item.servername}</td> <php>}</php> <td>{$item.ip}<br/>(<span id='severs_ws_port{$item.id}'></span>) <br/> [<span id='severs_ws_xinxi{$item.id}'></span>] </td> <php>if (in_array('ip_num',$list_fields_checked,true)) {</php> <td>{$item.ip_numbers}个--aa</td> <php>}</php> <php>if (in_array('share_type',$list_fields_checked,true)) {</php> <td>{$item['share_type']?'共享型':'独享型'}</td> <php>}</php> <!-- <php>if (in_array('server_name',$list_fields_checked,true)) {</php> <td>{$item.servername|default='-'}</td> <php>}</php> --> <td>{$item.lineName}</td> <php>if (in_array('cpu',$list_fields_checked,true)) {</php> <td>{$item.cpu}核</td> <php>}</php> <php>if (in_array('memory',$list_fields_checked,true)) {</php> <td>{$item.memory}G</td> <php>}</php> <php>if (in_array('harddisks',$list_fields_checked,true)) {</php> <td>{$item.harddisks}G</td> <php>}</php> <php>if (in_array('bandwidth',$list_fields_checked,true)) {</php> <td>{$item.bandwidth}M</td> <php>}</php> <php>if (in_array('user_id',$list_fields_checked,true)) {</php> <td> <a class="user-info-view" data-id="{$item.userid}">{$item.userid}</a> </td> <php>}</php> <php>if (in_array('buy_time',$list_fields_checked,true)) {</php> <td>{$item.buytime}</td> <php>}</php> <php>if (in_array('end_time',$list_fields_checked,true)) {</php> <td>{$item.endtime}</td> <php>}</php> <php>if (in_array('order_status',$list_fields_checked,true)) {</php> <td> <span class="state-label {$item.orderStatusNameCss}">{$item.orderStatusName}</span> </td> <php>}</php> <php>if (in_array('run_status',$list_fields_checked,true)) {</php> <td > <span class="state-label {$item.runStatusNameCss}">{$item.runStatusName}</span> </td> <php>}</php> <php>if (in_array('act_status',$list_fields_checked,true)) {</php> <td class="{$item.actStatusNameCss}"> <span class="state-label {$item.actStatusNameCss}">{$item.actStatusName}</span> </td> <php>}</php> <if condition="auth('service/detail')"> <td> <a href="{:U('admin/service/detail', array('id'=>$item['id']))}">管理</a> </td> </if> </tr> <script> $(function(){ let id = {$item.id}; console.log(id); $.get({ url:"{:U('admin/service/detail', array('id'=>$item['id']))}", // async:false, success:function(data){ let result = $(data).find("#wd_port").html(); let result11 = $(data).find("#bohao_xinxi").html(); console.log(result); $("#severs_ws_port{$item.id}").html(result); $("#severs_ws_xinxi{$item.id}").html(result11); } }) // console.log('321324324'); }) </script> </volist> </tbody>

detail.html

detail.html
<
th>远程端口:</th> <td >] <if condition="$server['share_type']"> {$server.public_ip}<if condition="$server['port']">:<span >{$server.port}</if></span> <if condition="$line_type eq 'local'"> <a href="{:U('admin/Control/manage', array('tab'=>'2','keyword'=>$server['id'],'keywordType'=>'serverID','id'=>$controller['id']))}">[管理]</a> | <a href="{:U('admin/ServerPort/add', array('id'=>$server['id'],'ip'=>$server['ip'],'guid'=>$server_master['controller_port_guid']))}">[申请]</a> </if> <if condition="$line_type eq 'zkeys'"> <!-- <a href="{:U('admin/Control/manage', array('keyword'=>$server['id'],'keywordType'=>'serverID','id'=>$controller['id']))}">[管理]</a> | <a href="{:U('admin/ServerPort/add', array('id'=>$server['id'],'ip'=>$server['ip'],'guid'=>$server_master['controller_port_guid']))}">[申请]</a> --> <a href="javascript:;" class="apply_port">申请公网端口</a> | <a href="javascript:;" class="open_detail">端口管理</a> </if> <else /> </if> <if condition="($line_type neq 'niaoyun') && $server['share_type'] && $account['account'] && $account['password'] "> <th>拨号信息:</th> <td style="max- 200px;word-break: break-all;"> <if condition="$account"> <span > {$account.account} , {$account.password}</span> </if> <if condition="($line_type eq 'local')"> <a href="javascript:;" id="modifyAccount">[修改拨号]</a> </if> </td> </if>

ajax 请求另一个html页面的指定的一部分 加载到本页面div