2

试图遵循一个linkedin的例子,但他们的代码似乎不起作用

当我将示例代码复制到 HTML 页面中时,它会呈现为

 Profile App Example

'); IN.parse(document.getElementById("profile")) }) }

我在萤火虫中得到这个错误

SyntaxError: unterminated string literal
[Break On This Error]   

e="IN/FullMemberProfile" data-id="' + result.values[0].id + '">

但我没有看到它(在示例代码中,所有引号都匹配)。

也得到这个错误

TypeError: $.cookie is not a function
[Break On This Error]   

...kie('quck-note-current', JSON.stringify({ "Id": id, "Note": note }), { expires: ...

编辑

这是他们拥有的完整示例代码。

<html>
<head>
<title>Profile App Example</title>

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: o1yf9WMdgd8dp_OGkmtXESCOJFostN8N1jI1AFKY2i0kJ1QFNMOs3a6R5qUoBIqF
  authorize: true
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5b1.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>  

<script type="text/javascript">

function loadData() {
IN.API.Profile("me")
   .result(function(result) { 
      $("#profile").html('<script type="IN/FullMemberProfile" data-id="' + result.values[0].id + '"></script>');
      IN.parse(document.getElementById("profile"))
   })
}

</script>

</head>
<body class="yui3-skin-sam     yui-skin-sam">
<div id="profile"></div>
<script type="IN/Login" data-onAuth="loadData"></script>
</body>
</html>

编辑 2

我尝试使用他们的 api 密钥并使用了我的 api 密钥(由于某种原因,比他们的示例短很多,但这就是它在 api 密钥下的应用程序区域中显示的内容)

4

1 回答 1

2

jQuery 在使用$(string).

这一行:

$("#profile").html('<script type="IN/FullMemberProfile" data-id="' + result.values[0].id + '"></script>');

需要</script>变得<\/script>,这就是为什么之前发现错误的原因:

'); IN.parse(document.getElementById("profile")) }) }

类似的讨论:How to get JavaScript script tags inside jQuery .html() function?

于 2013-07-04T22:19:42.883 回答