2011-06-22 98 views
0

我在.aspx页面中有下面的代码。将Facebook信息传递给HTML隐藏输入字段

<input type="hidden" id="fbinfo" name="fbinfo" value="" runat="server" /> 
<script src="Scripts/jquery.min.js"></script> 

<div id="fb-root"></div> 
<script src="Scripts/all.js"></script> 

<script> 
FB.init({ 
    appId: 'thisIsMyAppId', 
    status: true, 
    cookie: true, 
    xfbml: true 
}); 

FB.getLoginStatus(handleSessionResponse); 

function handleSessionResponse(response) { 
    if (!response.session) { 
     clearDisplay(); 
     return; 
    } 

    FB.api({ 
     method: 'fql.query', 
     query: 'SELECT uid, first_name, last_name, FROM user WHERE uid=' + FB.getSession().uid 
     }, 

     function(response) { 
      var user = response[0]; 
      var userInfo = document.getElementById('fbinfo'); 
      $('#fbinfo').html('user id is:' + user.uid); 
     } 
    ); 
} 

当我运行它,VS IDE抛出回一个错误信息,说

HTMLFILE:意外的调用方法或属性的访问。

这强调了jquery.min.js内的这部分代码

{if(this.nodeType==1){this.appendChild(E)} 

的问题是如何通过从查询以一个HTML输入隐藏式控制或ASP的FQL的值:控制(如标签或隐藏字段)?

回答

0

#fbinfo是一个input元素,因此,您不能在其中设置html(),而应该使用val()

像这样:

$('#fbinfo').val('user id is:' + user.uid); 

欲了解更多信息,看看在val() documentation

0

新增Facebook命名空间HTML标签:

xmlns:fb="http://www.facebook.com/2008/fbml" 

像:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
+0

spektom,我已经做到了。这不是这个问题,但谢谢。 – FBLover2011

相关问题