开发者

HTML string passed in to jQuery .append() function not displaying

I have an ajax call which returns the following HTML:

<form action="/Function.aspx/Add" method="post">
    <input id="Type" name="Type" type="hidden" value="Customer" />
    <input 开发者_开发知识库id="CustomerId" name="CustomerId" type="hidden" value="3" />


    <tr>
        <td>
            <input type="submit" value="Save" style="width:7em;" />
        </td>
        <td colspan="2">
            <select id="CustomerAppId" multiple="multiple" name="CustomerAppId">
    <option value="BA">Option 1</option>
    <option value="AB">Option 2</option>
    <option value="DC">Option 3</option>
       </select>
        </td>
    </tr>

</form> 

The ajax script performs great, and my result looks good in the alert() call:

<table id="appTable">
<tr>
    <th></th>
    <th><label for="AppId">ID</label></th>
    <th><label for="AppName">Description</label></th>
</tr> 

<tr>

    <td>  
    <a href="/Function.aspx/Remove/221?reqId=3">Delete</a>
    </td> 

    <td>PSE</td>
    <td></td>
</tr>

</table>        

<a href="/Function.aspx/BlankEditorRow/3?type=Customer" id="addItem">Add another...</a>

<script type="text/javascript">
$("#addItem").click(function () {
    $.ajax({
        url: this.href,
        cache: false,
        success: function (html) {

            alert(html);
            $("#appTable").append(html);
        },
    });
    return false;
});
</script>

However, my HTML never shows up.

I tried:

  • Replacing the html variable in the script to '<tr><td>Hello!</td></tr>': that works.
  • Removing all and tags, leaving the plain and contents: that did NOT work.
  • Added $(document).ready() to the beginning of the script: No change

I've been staring at this HTML trying to figure out what it doesn't like, and I'm just not seeing it. Any ideas?


Apparently, in order to properly evaluate the data from an ajax call, you need to wrap the result in a $().

So, when I changed this line:

$("#appTable").append(result);

To this:

$("#appTable").append($(result));

The row was added successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜