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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JSON Ajax request throwing error

(0) ShareShare
ReportReport
Posted on by 680

I keep getting the error 'SCRIPT1004: SCRIPT1004: Expected ';'' on the returned result.

Here is my code:

$.ajax({
type: "POST",
url: "">npiregistry.cms.hhs.gov/.../ + NPI + "",
dataType: "jsonp",
jsonpCallback: 'processJSONPResponse', // add this property
contentType: "application/json; charset=utf-8",
success: function(data) {
console.log(data);
},
error: function(data){
console.log(data);
}
});

I tried changing the method to GET and Changed the data type to JSON then it would throw CORS issue. Please suggest. Thanks.

I have the same question (0)
  • oliver.rodrigues Profile Picture
    4,052 on at
    RE: JSON Ajax request throwing error

    is this related to portals or crm?

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at
    RE: JSON Ajax request throwing error

    Hi Karthik,

    Could you share how would you like to integrate data from https://npiregistry.cms.hhs.gov/ within your Dynamics 365 environment?

    E.g: display them in web resource or  a web page of Portal? 

    The error told us that npiregistry has blocked XMLHttpRequest request from other websites/domains except itself.

    Please find whether there is setting in npiregistry to allow your website or domain to access its data.

    If you can't find such setting, it means that we couldn't get data from front-end, thus you need to get data with back-end method.

    You could use HTTP connector to request API(back-end way) and read its JSON body with other connectors without building a web application.

    e.g: Get Baltimore data from npiregistry.

     pastedimage1585821856851v1.png

    Regards,

    Clofly

  • Karthik Dayala Profile Picture
    680 on at
    RE: JSON Ajax request throwing error

    I do get CORS issue when I use the dataType json hence I switched it to jsonp. I'm trying this on a custom portal field on change event. The funny thing is my block of code executes but enters error with the status code 200.

    Here is my code:

    function getNPPESData() {

       var NPI = $('#nact_npi').val();

    if (NPI != null) {    

    $.ajax({

           type: 'GET',

                   url:      "npiregistry.cms.hhs.gov/.../ + NPI + "",

                   dataType: 'jsonp',

                   success: function(data) {

                      alert('success');

                   },

    error: function(data){

    alert('failed');

    }

      });

    }

    }

    The error on console when I debug:

    SCRIPT1004: SCRIPT1004: Expected ';'

    api (1,16)

    Here is my api response:

    {"result_count":1, "results":[{"enumeration_type": "NPI-1", "number": 1316459605, "last_updated_epoch": 1508976000, "created_epoch": 1508976000, "basic": {"first_name": "BIANCA", "last_name": "AARON", "credential": "MFTI, PCCI", "sole_proprietor": "NO", "gender": "F", "enumeration_date": "2017-10-26", "last_updated": "2017-10-26", "status": "A", "name": "AARON BIANCA"}, "other_names": [], "addresses": [{"country_code": "US", "country_name": "United States", "address_purpose": "LOCATION", "address_type": "DOM", "address_1": "1540 E COLORADO ST", "address_2": "", "city": "GLENDALE", "state": "CA", "postal_code": "912051514", "telephone_number": "818-244-7257", "fax_number": "818-243-5431"}, {"country_code": "US", "country_name": "United States", "address_purpose": "MAILING", "address_type": "DOM", "address_1": "4760 SEPULVEDA BLVD", "address_2": "", "city": "CULVER CITY", "state": "CA", "postal_code": "902304820", "telephone_number": "310-390-6612", "fax_number": "310-398-5690"}], "taxonomies": [{"code": "106H00000X", "desc": "Marriage & Family Therapist", "primary": true, "state": "", "license": ""}], "identifiers": []}]}

  • Karthik Dayala Profile Picture
    680 on at
    RE: JSON Ajax request throwing error

    this is on portal field on change event.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: JSON Ajax request throwing error

    Hi Karthik,

    Because the website "https://npiregistry.cms.hhs.gov/" has blocked CORS request, so you need a intermediate server to help you handle request, 

    which means it will send request to hhs.gov, then the server will forward result to you. (like a Proxy)  

    There are some serverless solutions to meet your requirement.

    1. Free public CORS forward service:

    https://cors-anywhere.herokuapp.com/

    https://github.com/netnr/workershttps://cors.zme.ink/ * )

    Usage:

    url: serverUrl/apiEndpoint

    Here is my demo, run the request by clicking a button.

    $.ajax({
    
        type: 'GET',
    
        url: "https://cors-anywhere.herokuapp.com/https://npiregistry.cms.hhs.gov/api/?version=2.0&number=1316459605",
    
        // url: "https://cors.zme.ink/https://npiregistry.cms.hhs.gov/api/?version=2.0&number=1316459605",
    
        // only required when using the first url 
        beforeSend: function(request) {
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          },
    
        success: function (data) {
            console.log(data.results[0]);
        },
    
        error: function (data) {
            alert('failed');
        }
    
    });
     

    result:

    pastedimage1585892540538v3.png

    2. Create your own proxy server with Cloudflare Worker service, the second service(*) is built on it.

    https://workers.cloudflare.com/

    demo project:

    https://github.com/Zibri/cloudflare-cors-anywhere

    Regards,

    Clofly

  • Karthik Dayala Profile Picture
    680 on at
    RE: JSON Ajax request throwing error

    Thank you.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 120 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 119

#3
Erin Lubben Profile Picture

Erin Lubben 73

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans