为什么在示例SDK脚本中出现javascript错误

Why getting javascript errors with sample SDK script?

本文关键字:javascript 错误 脚本 SDK 为什么      更新时间:2023-09-26

我在dynamics CRM中创建了以下简单的web资源,使用OData使用rest API。请考虑,new_JavaScriptRESTDataOperationsSample是带有SDK的示例,我只创建了以下示例HTML。

<HTML><HEAD><TITLE>OData</TITLE>
<META charset=utf-8></HEAD>
<BODY>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript src="new_SDK.REST"></SCRIPT>
<SCRIPT type=text/javascript src="new_json2"></SCRIPT>
<SCRIPT type=text/javascript src="new_JavaScriptRESTDataOperationsSample"></SCRIPT>
<BUTTON onclick=createAccount();>Click Me!</BUTTON></BODY></HTML>

当我点击点击我按钮会出现以下错误,

网页错误详细信息

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR
3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3) Timestamp: Mon, 29 Sep 2014 07:38:45 UTC

Message: 'startButton' is null or not an object Line: 32 Char: 3 Code: 0 URI: http://dynamicscrm01/CRM01/%7B635475719080000809%7D/WebResources/new_JavaScriptRESTDataOperationsSample

Message: 'output' is null or not an object Line: 199 Char: 2 Code: 0 URI: http://dynamicscrm01/CRM01/%7B635475719080000809%7D/WebResources/new_JavaScriptRESTDataOperationsSample

很抱歉格式不正确,所以不允许在块引号中使用链接。

MSDN示例sample_/Scripts/JavaScriptRESTDataOperationsSample连接到sample_/JavaScriptRESTDataOperationsSample.htm web资源。

示例:使用JavaScript 的OData端点创建、检索、更新和删除

如果你查看CreateAccount函数内部,你会发现以下行:

startButton = document.getElementById("start");
output = document.getElementById("output");

因此脚本期望在HTML文件中存在这些对象。在您的示例中,您只包含按钮,但sample_/JavaScriptRESTDataOperationsSample.htm web资源包含请求的对象:

<button id="start" title="Click this button to start the sample.">
  Start</button>
 <button id="reset" title="Click this button to reset the sample." disabled="disabled">
  Reset</button>
 <ol id="output">
 </ol>