cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Deep
Helper I
Helper I

Failed to load response data when tried to get access token from azure using javascript

I want to get an Access token of my registered application on azure. To do so I wrote a piece of code to hit the rest-API.

This is my code:

<html>
<head>
  <title>Test</title>   
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.12/js/adal.min.js"></script>
  <script src="/static/powerbi.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>        
  </head>
<body>
  <div id="captionArea">
    <h1>Power BI Embed test</h1>
  </div>
  <div id="embedContainer" style="height:500px">
  </div> 
  <script>    (function () {

    var reportId = 'cbd6b049-8c11-4fca-a4ac-762317b5bc54'
    var groupId  = 'e6670d37-8784-400b-8c8d-57a5dc023b60'   //workspace_id
    var datasetId = 'dc07c338-a9d3-4cfb-ac98-8daf40706dc8'
    
    
   var settings = {
  "url": "https://login.microsoftonline.com/041ba837-1928-46ad-98e6-a87e0c0b4b41/oauth2/token",
  "method": "POST",
  "crossDomain": true,
  "dataType": 'jsonp',
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "client_id": "6b7f8e3c-0551-4ac9-b9eb-b1dd34e5817c",
    "username": "Pbiembed@scopeworker1.onmicrosoft.com",
    "password": "pbiMusa0775",
    "grant_type": "password",
    "resource": "https://analysis.windows.net/powerbi/api"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
}); 
}());
  </script>
</body>
</html>

 and after this, I got a response. In the console, under the header section I got status: 200 and request method: GET but in my code, the request method is "POST", and In the response section it shows "This request has no response data available" :

Screenshot (76).png

 

Screenshot (77).png

I don't know, why I am not getting any response and how my request method changes from "POST" to "GET"?

0 REPLIES 0

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.