I have been working on a local web service that I believe fits the criteria for making cross-domain JavaScript calls to access external data within Dynamics CRM. However, I am facing some challenges in creating the JavaScript AJAX code needed to connect with this external web service.
By accessing the web service at , I was able to generate the results displayed in Screen Shot 1 below:
The main issue I'm encountering is figuring out how to correctly write the JavaScript code to fetch the serialized items from the web service mentioned above.
Upon running the page and clicking the "test" button, I receive an error message stating '0x800a1391 - JavaScript runtime error: 'GetJSONP' is undefined.'
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ClientSideGeneralTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/.../xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript" type="text/JavaScript" src="Scripts/jquery-3.1.1.min.js">
function GetJSONP() {
debugger;
$.ajax({
url: "aloyegeneraltest1/.../GetPriceJSON",
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{"name":' + JSON.stringify(GetData()) + '}'
}).done(function(result) {
alert(result.d);
}).fail(function(result) {
alert(result.d);
});
}
}
</script>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button"
value="Test" onclick="GetJSONP()" /><br />
</div>
</form>
</body>
</html>
If I remove the JQuery reference entirely, it eliminates the undefined function error mentioned earlier, but it leads to a new unhandled exception error: '0x800a1391 - JavaScript runtime error: '$' is undefined.'
This is the modified code snippet that triggers the new error:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ClientSideGeneralTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/.../xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript" type="text/JavaScript">
function GetJSONP() {
debugger;
$.ajax({
url: "aloyegeneraltest1/.../GetPriceJSON",
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{"name":' + JSON.stringify(GetData()) + '}'
}).done(function(result) {
alert(result.d);
}).fail(function(result) {
alert(result.d);
});
}
</script>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button"
value="Test" onclick="GetJSONP()" /><br />
</div>
</form>
</body>
</html>
The issue seems to be related to the use of '$' at the beginning of the Ajax code block.
As someone who is new to AJAX and relatively new to development as a whole, any help or advice offered would be highly appreciated.