?Briella 2014-02-13 00:04 采纳率: 0%
浏览 29

jQuery Ajax获取Div

I'm having trouble with ajax response.

my .php file generates a table

    <div class="result">
        <tr class="distr">
           <td><input name="somename" value="value"></input</td>
           <td>..more input</td>
           ...more <tds>
       </tr>
    <div>

.js file

//...unrelated code up here

$.ajax({
    type: "POST",
    url: "myphpfile.php",
    data: "data that creates table",
    success: function(r) {
        var getdata = $(r).filter(".result");
        console.log(getdat);
    }
});

my main file has

<table class="tbl">
   <tr>
       <td><input></input></td>
       ...
   </tr>
</table>

I'm trying to get the table that is generated by my php file to be appended to

<table class="tbl">

but the response I get is only

<input>...</input>
<input>...</input>
some other div children here
<input>...</input>
some text

instead of everything in

<div class="result">

Can someone explain to me how this works. I've also tried .find(".result") instead of .filter() Oh and I dont want that div returned, just the table inside of it.

Sorry if this is hard to understand, all this looks weird as I'm typing.

Thanks

  • 写回答

2条回答 默认 最新

  • 关注

    Try using jQuery.get ()

    $.get( "myphpfile.php", { param1: "p1", param2: "p2" } )
        .done(function( data ) {
        var content = $( data ).find( ".result" );
    });
    

    Update:

    $(".result").load("myphpfile.php .result", { param1: "p1", param2: "p2" })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退