未捕获的异常对象#<objectid>没有方法'html'</objectid>

时间:2012-07-08 06:54:49

标签: jquery html javascript-events

我收到此消息

  

未捕获的异常对象#displayusersearch2没有方法'html'

代码是

<script src="../../javascript/jqueryfunctions.js" type="text/javascript"></script>
<script src="../../jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function uid_id_search_change()
{
    var search=document.getElementById('uid_id_search').value;
    $.get('userdisplaypopup.php?id='+search,userset);
 }

 function userset(res)
 {
     ('#displayusersearch2').html(res);
     Uncaught TypeError: Object #displayusersearch2 has no method 'html'
 }
 </script>

 <table width="600" border="0">
     <tr>
         <th scope="row"><font size="-1">Book Id</font></th>
         <td><input type="text" value="1" id="bid_popup" /></td>
     </tr>
     <tr>
         <th scope="row"><font size="-1">Book Name</font></th>
         <td><input type="text" value="1" /></td>
      </tr>
      <tr>
          <th scope="row"><font size="-1">Author</font></th>
          <td><input type="text" value="1" /></td>
      </tr>
      <tr>
          <th scope="row"><font size="-1">Publisher</font></th>
          <td><input type="text" value="1" /></td>
      </tr>
      <tr>
          <th scope="row">Search User</th>
          <td><input type="text" id="uid_id_search" name="uid_id_search" onkeyup="uid_id_search_change();" />
          <div id="displayusersearch2"></div></td>
      </tr>
</table>

div的id是displayusersearch2。请求正在正确发送。我试图让响应显示在div displayusersearch2

1 个答案:

答案 0 :(得分:4)

('#displayusersearch2')

您省略了{J}包装器调用的$。没有它,这只不过是一个字符串文字。字符串'#displayusersearch2'没有html()方法。

$('#displayusersearch2').html(res);

此外,

$.get('userdisplaypopup.php?id='+search,userset);
对于任何带有URL特殊字符的search字词,

将失败。建议使用encodeURIComponent(),或让jQuery为你做:

$.get('userdisplaypopup.php', {id: search}, userset);