Error in JSON format detected in cross-origin request

My code snippet:

$.getJSON('http://../id=1397391950253&callback=?', null, function (results) {
            alert('Successfully achieved a cross domain JS call');
});

The result obtained is as follows:

{
    "data": [{
        "shiftY": 0,
        "regType": "FAS",
        "fuelVolume": 2373,
        "eventDate": 166625019,
        "gsmOn": true,
        "bigIconHeight": 21,
        "speed": 17,
        "roamingOn": false,
        "direction": 134,            
        "latitude": 54.8658849,
        "bigShiftY": 0,
        "iconHeight": 28,
        "useDiscreteOutput": false
    }],
    "reportDescriptor": {
        "reportTypeID": 2,
        "objectTypes": ",FAS,FTC",
        "dependencyType": "vehicle"
    }
}

However, I encountered an error in Chrome that says "Uncaught SyntaxError: Unexpected token : rtmap:1". What could be the issue with the result?

Answer №1

Performing a cross domain request can be achieved through either JSONP or CORS.

It is recommended to utilize JSONP, where the returned result should be wrapped in a function named callback (Note that the function name can be customized by modifying the query parameter callback in the request, for example: &callback=myCustomCallback). Your server response should follow this format:

callback({
    "data": [{
        "shiftY": 0,
        "regType": "FAS",
        "fuelVolume": 2373,
        "eventDate": 166625019,
        "gsmOn": true,
        "bigIconHeight": 21,
        "speed": 17,
        "roamingOn": false,
        "direction": 134,   
        "latitude": 54.8658849,
        "bigShiftY": 0,
        "iconHeight": 28,
        "useDiscreteOutput": false
    }],
    "reportDescriptor": {
        "reportTypeID": 2,
        "objectTypes": ",FAS,FTC",
        "dependencyType": "vehicle"
    }
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML5 Embedding a redirect iframe for connection status validation [UPDATE]

I've created an offline HTML file and embedded an iframe within it that redirects to a site if there is an available internet connection. However, in the event of no internet connection, the iframe will redirect to an offline page. Could someone plea ...

Decoding JSON Data in PHP to Work with Arrays and Objects

Among the plethora of JSON/PHP/Decode related posts out there, I find myself struggling. It's apparent to me that I've made a mistake in constructing my JSON, but despite my efforts, I can't pinpoint where I went wrong. Can anyone offer some ...

Break down the execution process of the intricate JavaScript return statement

I am struggling to understand the execution flow of this return statement. If someone could clarify how it works and perhaps discuss the advantages and disadvantages of using such a complex statement instead of a more readable multi-line statement, I wou ...

The data points on the Google Maps heatmap are not visible

We are working on developing a server side application that will utilize the Google Maps API to create weighted heat maps for visualizing data. Check out the Google Maps API documentation for Heat Maps here Despite successfully displaying the map, my Jav ...

Is it feasible to include the password in JSON format, along with other information, when using Magento 2 REST API for customer registration?

When attempting to register a new Customer on my Magento portal using the REST API in Postman, I encountered an issue. The standard approach for Magento API registration only allows certain details to be sent via the POST Method; password cannot be include ...

Deserializing Nested JSON Objects in Delphi 2012

I am currently developing a wrapper for Dropbox in Delphi 2012. One issue I am facing is the deserialization of JSON responses. When requesting a list of folders and files from my account, the response looks like this: { "hash": "some_hash", "thum ...

The error code ELIFECYCLE occured while attempting to install the Shopify starter-theme-master using npm

Hello everyone, I am brand new to the world of coding and I consider myself an absolute beginner. Currently, I am diving into learning Shopify Theme Development, and I have encountered an issue while trying to install NPM Run Dev using some sample code. De ...

Ways to retrieve the most recent message on WhatsApp Web

I'm currently developing a JavaScript script for WhatsApp Web that will automate responses to messages in a specific group. Here is a snippet of my code: console.log('WhatsappWeb On'); function sleep(num){ setTimeout(num); } var eve ...

Differences between referencing and valuing in arrays in JavaScript

I have noticed an interesting behavior when passing arrays to functions by reference. Even after modifying the array inside a function, the changes do not reflect when logging the array outside the function. For example: let arr = [1, 2]; console.log(arr ...

Learning to master each individual jQuery method is an essential skill for any web developer

I'm working with the following function but $('input[id^="ProductId_"]').each(function () { it's giving me a different output than what I need. The desired result should be obtained from $('input[id^="ProductId_"]').cli ...

Is there a simple method to submit to a URL without relying on ajax?

When it comes to using jQuery, the $.ajax() function is typically used for POST requests to a URL. However, in my particular situation, I am unable to use this function. I need the client to send a POST request to a URL and have the server redirect the use ...

Display or conceal HTML content based on the input's property type

Looking to toggle the visibility of an icon on my input based on the prop type. If the type is set to password, the icon will be displayed for toggling between visible and hidden password; if the type is not password, the icon should be hidden by setting ...

The deletion of property '1' from the [object Array] is not possible

How to Retrieve a List in My Components Using Input : @Input() usersInput: Section[]; export interface Section { displayName: string; userId: number; title: number; } Here is the Value List : 0: displayName: "بدون نام" ...

Combining Two JSON Arrays Featuring Unique Keys

I have two JSON arrays with slightly different keys. The first JSON array contains the keys id, name, and title. The second JSON array includes id, title, forename, name, and company. I am wondering if it's possible to merge these two arrays so th ...

Is there a way to dynamically set CSS variables within media queries using a JavaScript object?

Trying to pass a CSS variable into a media query for my Next.js project using theme-ui's sx property. I have styles set up like this: const styles = { headerLinkContainer: { width: '500px', justifyContent: 'space-ev ...

Display a series of messages using an Angular directive

Here is a sample HTML code: <section class="correspondence"> <header> <div class="from">{{ message.from }}</div> <div class="when">{{ message.when }}</div> </header> <div class="content"> { ...

Enhance the efficiency of your JavaScript code by minimizing repeated selectors

I've been working on a JavaScript project where I came across the following lines of code: $('#content').on('click', 'input[type=submit]', function(){ $('#content').on('click', 'a.removebutton&a ...

JavaScript code for iframe auto resizing is not functioning properly on Firefox browser

I have implemented a script to automatically resize the height and width of an iframe based on its content. <script language="JavaScript"> function autoResize(id){ var newheight; var newwidth; if(document.getElementById){ newh ...

Ways to navigate to a new webpage in JavaScript without the need to click on a link

After going through various posts and trying different methods, I am still facing challenges. In a PHP page, I have an HTML form with an onClick command that triggers a JavaScript validation procedure when the user clicks a button. While everything funct ...

What steps should I take to fix the error message "Uncaught TypeError: Class constructor m must be called with 'new'" that occurs while attempting to access a polymer v2.0 application?

Is there a way to resolve this error that occurs when attempting to open a Polymer v2.0 app on Safari in iOS? Uncaught TypeError: Class constructor m cannot be invoked without 'new' from custom-elements-es5-adaptor. The Polymer v2.0 starter k ...