web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

access external service url throws error Undefined - Need help for JS function

(0) ShareShare
ReportReport
Posted on by 1,345

Hello experts,

I am trying to access external service url using javascript but it throws undefined as an alert instead of json response. Can some one pls tell me where is going WRONG in the below JS function. And i am able to access my data correctly in the browser as json response string format data. Please help for this webresource.... can some one please point me right path as i need to generate table with this json response runtime in html table format.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!--<script src="jquery-1.7.1.js" type="text/javascript"></script>-->
<script type="text/javascript" src="../WebResources/eb_xrmjquery"></script>
<script type="text/javascript">
$(document).ready(function ()
{
});
var GetJson = function ()
{
var requestdata = {};

$.ajax({
type: "GET",
//data: JSON.stringify(),
url: "localhost/.../0000003049",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function ()
{
alert(data);
},
error: function (xhr)
{
alert(xhr.responseText);
}
});
}

</script>
</head>
<body>
<br />
<input type="button" id="jsonButton" onclick="GetJson()" value="Bind JSON" />
<br />
<br />
<div id="jsonData">
</div>
</body>
</html>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    DH kumar CRM Profile Picture
    1,345 on at

    Hello All,

    By doing some R & D for the above mentioned issue i am able to get/Display data locally by following this in Table/TR/TD format with the use of below code but not in the CRM web resource and thought to share the same for reference. In CRM still gettting UNDEFINED error for HTML webresource. Please let me know for cross domain external service url accessibility in CRM web resource HTML.

    <html lang="en" xmlns="www.w3.org/.../xhtml&quot;>

    <head>

       <meta charset="utf-8" />

       <title></title>

       <!--<script src="ajax.googleapis.com/.../jquery.min.js&quot;></script>-->

       <script type="text/javascript" src="../WebResources/eb_xrmjquery"></script>  

       <script type="text/javascript">

           function ShowData() {

               debugger;

               //$.support.cors = true;

               jQuery.support.cors = true;

               $.ajax({

                   url:"server/.../0000003049&quot;,

                   type: "GET",

                   contentType: "application/json; charset=utf-8",

                   dataType: "json",

                   success: function (data) {

                       debugger;

                       alert(data);

                       $("#tdHInsurance").text(data.HInsurance);

                       $("#tdAccountType").text(data.AccountType);

                       $("#tdActiveLoan").text(data.ActiveLoan);

                       $("#tdIndexName").text(data.IndexName);                    $("#tdCurrentPrincipalBalance").text(data.CurrentPrincipalBalance);

                   },

                   error: function (xhr, error, status) {

                       alert(xhr.responseText);

                   }

               });

           }

       </script>

    </head>

    <body>

       <input type="button" value="ShowData" onclick="ShowData()" />

       <table>

           <tr>

               <td>HInsurance</td>

               <td id="tdHInsurance"></td>

           </tr>

           <tr>

               <td>Account Type</td>

               <td id="tdAccountType"></td>

           </tr>

           <tr>

               <td>Active Loan</td>

               <td id="tdActiveLoan"></td>

           </tr>

           <tr>

               <td> Index Name</td>

               <td id="tdIndexName"></td>

           </tr>

           <tr>

               <td>Current Principal Balance</td>

               <td id="tdCurrentPrincipalBalance"></td>

           </tr>

       </table>

    </body>

    </html>

  • Suggested answer
    DH kumar CRM Profile Picture
    1,345 on at

    For this issue, i have referred this url but not helped. seems nicely explained - salimadamoncrm.com/.../making-cross-domain-ajax-calls-from-crm-form-jscript  

    Tried to put & apply this in my code as mentioned in this above url

    First, some browsers will simply not allow jQuery AJAX requests to run if they are made to a domain different than that of the running web application. The reason behind is that not all browsers can create XMLHttpRequest objects that have a withCredentials property. That is used to specify that we want to include the user credentials in a cross domain request. To always have that working, jQuery has the solution for us. Use the following statement in the code before making the AJAX call: jQuery.support.cors = true;

    Can some one suggest apart from this or if there is anything missing to get this done...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans