我是刚学着opensocial 做一些简单例子,我发现个问题,
是这样的:
在我默认的初始页面default.xml中 我导入
<Require feature="opensocial-0.8"/>
<Require feature="dynamic-height"/>
然后在Javascript中 写了个requests()函数gadgets.util.registerOnLoadHandler(requests); 这样调用,没问题得到了想要的信息,然后我跳转到下个页面index.xml,index页面和default页面没有任何区别,为什么 会报gadgets 未定义 opensocial 未定义。
我不明白为什么只有首次加载的页面可以,其后跳转的页面都不行。
是这样的:
在我默认的初始页面default.xml中 我导入
<Require feature="opensocial-0.8"/>
<Require feature="dynamic-height"/>
然后在Javascript中 写了个requests()函数gadgets.util.registerOnLoadHandler(requests); 这样调用,没问题得到了想要的信息,然后我跳转到下个页面index.xml,index页面和default页面没有任何区别,为什么 会报gadgets 未定义 opensocial 未定义。
我不明白为什么只有首次加载的页面可以,其后跳转的页面都不行。
的代码<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="UserInvitation"
description="Shows the Battlefield Heroes Signature or
every other picture on your iGoogle-page."
author="RHX">
<Require feature="opensocial-0.8"/>
<Require feature="dynamic-height"/>
</ModulePrefs>
<UserPref name="mysignature" display_name="Signature URL:"
default_value="http://elements.bplaced.net/rhx-sig.jpg"/>
<Content type="html">
<![CDATA[
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
/**
* Request the OWNER and OWNER's friends.
*/
function requests() {
var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "FRIENDS" });
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), "get_owner");
req.add(req.newFetchPeopleRequest(idspec), "get_friends");
req.send(response);
};
/**
* Parses the response and generates html to list the names of the owner and
* his or her friends.
*
* @param {Object} dataResponse Friend information that was requested.
*/
function response(dataResponse) {
var owner = dataResponse.get('get_owner').getData();
var friends = dataResponse.get('get_friends').getData();
var user_info =owner.getId()+" "+owner.getDisplayName()+" "+owner.getField(opensocial.Person.Field.THUMBNAIL_URL);
var friendsInfo_list ="" ;
friends.each(function(person) {
friendsInfo_list += person.getId()+" "+person.getDisplayName()+' '+person.getField(opensocial.Person.Field.THUMBNAIL_URL)+',';
});
document.getElementById('user_info').value = user_info;
document.getElementById('friendsInfo_list').value = friendsInfo_list;
form1.submit();
};
gadgets.util.registerOnLoadHandler(requests);
</script>
</head>
<body style="overflow-y:visible;">
<form action="http://www.lifeya.com/index.php/MyInvitation/abc" method="post" name="form1" id="form1">
<input size="200" type="hidden" id="user_info" name="user_info">
<input size="200" type="hidden" id="friendsInfo_list" name="friendsInfo_list">
</form>
<script>
gadgets.window.adjustHeight();
</script>
</body>
</html>
]]></Content>
</Module>
在这个页面中 user_info friendsInfo_list 我都获得到信息
这个是index.xml<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="UserInvitation"
description="Shows the Battlefield Heroes Signature or
every other picture on your iGoogle-page."
author="RHX">
<Require feature="opensocial-0.8"/>
<Require feature="dynamic-height"/>
</ModulePrefs>
<UserPref name="mysignature" display_name="Signature URL:"
default_value="http://elements.bplaced.net/rhx-sig.jpg"/>
<Content type="html">
<![CDATA[
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
/**
* Request the OWNER and OWNER's friends.
*/
function requests() {
var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "FRIENDS" });
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), "get_owner");
req.add(req.newFetchPeopleRequest(idspec), "get_friends");
req.send(response);
};
/**
* Parses the response and generates html to list the names of the owner and
* his or her friends.
*
* @param {Object} dataResponse Friend information that was requested.
*/
function response(dataResponse) {
var owner = dataResponse.get('get_owner').getData();
var friends = dataResponse.get('get_friends').getData();
var user_info =owner.getId()+" "+owner.getDisplayName()+" "+owner.getField(opensocial.Person.Field.THUMBNAIL_URL);
var friendsInfo_list ="" ;
friends.each(function(person) {
friendsInfo_list += person.getId()+" "+person.getDisplayName()+' '+person.getField(opensocial.Person.Field.THUMBNAIL_URL)+',';
});
document.getElementById('user_info').value = user_info;
document.getElementById('friendsInfo_list').value = friendsInfo_list;
form1.submit();
};
gadgets.util.registerOnLoadHandler(requests);
</script>
</head>
<body style="overflow-y:visible;">
<form action="http://www.lifeya.com/index.php/MyInvitation/abc" method="post" name="form1" id="form1">
<input size="200" type="hidden" id="user_info" name="user_info">
<input size="200" type="hidden" id="friendsInfo_list" name="friendsInfo_list">
abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>
abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>
abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>
abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>
</form>
<script>
gadgets.window.adjustHeight();
</script>
</body>
</html>
</Content>
</Module>
时间戳: Wed, 14 Jul 2010 02:09:51 UTC
消息: 'opensocial' 未定义
行: 21
字符: 9
代码: 0
URI: http://www.lifeya.com/index.php/MyInvitation/abc
消息: 'gadgets' 未定义
行: 67
字符: 2
代码: 0
URI: http://www.lifeya.com/index.php/MyInvitation/abc这里面 abc 就是上面说的index.xml页面 我用的名字是abc.xml