Issue found (in promise): Invalid Syntax detected at script.js line 8, character 42

I am in the process of developing a tool that retrieves ROBLOX asset IDs using this particular API. I am utilizing the product info function through an API GET request. Despite being near completion, I keep encountering the error

Uncaught (in promise) SyntaxError: Unexpected end of input at script.js:8:42
.

If anyone could lend a hand, I would greatly appreciate it!

Below is a link to my code.

JavaScript Code

function convert()
{
    var input = document.getElementById("AssetConverterArea").value;
    var output = document.getElementById("assetIdReturn");
    var webRequest = fetch('https://api.roblox.com/marketplace/productinfo?assetId=' + input, {'mode': 'no-cors'});
    var assetId = webRequest.AssetId;

    webRequest.then(responce => responce.json()).then(d => {
            console.log(responce)
            assetId = d.AssetId;
        });

    if (assetId === undefined)
    {
        output.innerHTML = "Invalid Asset ID";
    } else {
        output.innerHTM = 'Your asset ID is: ' + assetId;
    }
}

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
    <link rel="icon" type="image/x-icon" href="Media/assetid.png">
    <link rel="stylesheet" href="style.css">

    <script src="script.js" defer></script>
</head>
<body>
    <header>
        <nav>
            <ul class="navLinks">
                <li class="navLink"><a href="index.html" class="navHref">Home</a></li>
                <li class="navLink"><a href="credits.html" class="navHref">Credits</a></li>
                <li class="navLink"><a href="about.html" class="navHref">About</a></li>
            </ul>
        </nav>

        <span class="favicon"><img src="Media/assetid.png" alt=""></span>
    </header>

    <div class="line"></div>

    <h1 class="title">Asset Converter</h1>

    <p class="description">
        This website is a simple tool to convert your Roblox decal & library IDs into Roblox Asset IDs. <br><span style="font-weight: 800;"> Thank you for checking out the website!</span>  
    </p>
        
    </p>

    <div class="AssetDiv"><textarea placeholder="Decal ID" id="AssetConverterArea"></textarea></div>

    <button class="convertButton" onclick="convert()"><span class="convertText">Convert</span></button>

    <p id="assetIdReturn">Convert your ID, and get a return!</p>

    <p class="sourceCode">This entire project's source code is free for you to check out on <a style="color: rgb(73,0,250); text-decoration: none;" href="https://github.com/hartleyfr/RobloxAssetReturner/tree/main">my github</a></p>
</body>
</html>

I attempted to utilize CORS-Everywhere functions without success. Despite trying fixes from StackOverflow, the issue remains unresolved.

The expected behavior was as follows:

Retrieve the API return and table, locate the asset ID in the table, if the assetId cannot be found, display a message stating that the ID is invalid and prompt for another attempt. If found, display it to the user.

Answer №1

Your request is facing several challenges when it comes to resolving promises, but in simple terms, the concept you are trying to achieve is not feasible due to CORS restrictions in the browser settings. Disabling CORS at a browser level is not allowed for security reasons and cannot be done from a web page.

By using the request mode no-cors, the response becomes inaccessible to your JavaScript code. More information can be found at https://developer.mozilla.org/en-US/docs/Web/API/Request/mode

Unfortunately, the fetch operation will not be successful as the API does not allow cross-domain servers to make requests.

Answer №2

To achieve this task, you must initiate the ROBLOX API call from a server (such as a Node.js server) and enable your HTML page to communicate with the server (a straightforward method would involve setting up a CORS proxy as suggested in this solution )

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

Difficulty in comparing passwords using bcrypt encryption method

As a beginner in express js, I have successfully implemented the register functionality in my app. However, I am facing an issue with the login process. I am trying to compare the password stored in the database with the one provided by the user using bcry ...

Switching the horizontal tab design from Bootstrap 3 to Bootstrap 4

I'm currently working on adapting a code snippet from bootsnip that creates horizontal Bootstrap tabs with material-style design. I've encountered some challenges in converting it to Bootstrap 4, specifically in updating the CSS to use .nav-item ...

Loading and refreshing iframe content in real-time using JQuery on change() and keyup() events

I have been tackling a unique challenge with my custom CMS in Drupal for a couple of weeks now. I am facing an issue where I need to dynamically load a URL by extracting the node ID from the target Drupal page and appending it to the base URL of the websit ...

What is the best way to design a cell that overlaps with another?

I'm trying to figure out how to make a cell that spans the full width of the existing column and sits on top of the nearest cell. This is part of an effort to create a percentage graph. For example: https://i.sstatic.net/XZahG.png I've experim ...

What is the best way to extract a nested array of objects and merge them into the main array?

I've been working on a feature that involves grouping and ungrouping items. A few days ago, I posted this question: How can I group specific items within an object in the same array and delete them from the core array? where some helpful individuals ...

Steps for initializing input field with pre-existing values using Redux form

After reviewing the Redux Form documentation, I noticed that the example provided only fetches initial values upon button click. However, my requirement is to have these values available immediately when the page loads. In my current setup, I can successf ...

jquery module for retrieving and updating messages

I want to develop a custom plugin that can be utilized in a manner similar to the following example. This isn't exactly how I plan to use it, but it serves as the initial test for me to fully grasp its functionality. HTML: <div id="myDiv">< ...

The file uploader on the HTML page only allows for PNG files to be uploaded

Currently, I am working on an application where I am facing a challenge related to file uploads. Specifically, I have an input field like this: <input id="full_demo" type="hidden" name="test[image]"> I am looking for a way to restrict the upload of ...

When an input is double-clicked, the message"[object object]" appears on the screen

Here is the structure of the template used for the directive. Our code fetches data from a service which contains all the details of a specific individual. We display only the first name, last name, and either designation or company affiliation from that d ...

Connects URLs to the displayed outcomes in jQuery Auto-suggest Interface

This particular code snippet has been modified from a tutorial on jQuery autocomplete <!doctype html> <html lang="en> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> ...

How can you ensure in Typescript that a function parameter belongs to a specific set of enumerated values?

Consider this example enum: export enum MyEnum { a = "a", b = "b", c = "c" } Now, let's define a function type where the parameter must be one of these values. For instance, myFunction("c") is acceptabl ...

Tips for showing an image in a pop-up window using Window.open

I'm attempting to show an image in a popup window using the following JavaScript code: function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=no,t ...

What are the advantages of retrieving a complete category tree, including all categories and sub-categories, versus retrieving only the necessary branches as required?

My query is not centered around terminology accuracy, but rather on the goal of presenting a tiered structure consisting of categories, sub-categories, and sub-subcategories. In total, there are approximately 100 different categories and their respective ...

Troubleshooting issue with refreshing selectpicker in Bootstrap-select and Vue.js

Incorporating the bootstrap-select plugin (found at ) into a ruby on rails app with Vue.js as the javascript framework has been my latest project. The goal is to have two select options where one selects a category and the other displays all available tea ...

Navigate to a specific URL path and send properties as arguments in the function for handling events

I am working on a vuetify autocomplete search feature. When a user selects an item, I need to navigate to a specific route and pass some props along. However, my attempts to change the current route without passing props have resulted in errors. Here is w ...

What causes my slider to speed up with an increase in items and slow down with fewer items in bxslider?

Find more information here jQuery('.homepage_slider').bxSlider( { minSlides: 1, maxSlides: 4, slideWidth: 200, slideMargin: 30, ...

The o-gradient feature is not compatible with Mac and Linux operating systems

Hello there! I am facing an issue with creating a gradient on my website without using an image. Surprisingly, the gradient appears on Windows but not on Mac or Linux operating systems. Any idea why this might be happening? You can check out the website he ...

Why bother re-rendering components in React that haven't had any changes in their state?

Within my main component, I have both a state and a static component nested inside. An issue arises when the state changes and triggers a re-render of the main component, causing the static component to also re-render unnecessarily. import { useState } fro ...

Unexpected format of _id is returned by Mongolian DeadBeef .toArray() method

My love for Mongolian deadbeef is strong, but I'm facing a challenge. I want the output of a simple .find() method to match the JSON format from Mongo's command line: $ db.mycollection.find(); # outputs.. # { ...some data... , "_id" : ObjectId(" ...

Comparing attribute selectors to class selectors in the realm of styling

I often come across code that looks like this: <input type="text" class="class1" name="text"> <input type="submit" class="class2" name="submit"> which is then styled as follows: input[type=text] { styles here...} input[type=submit] { sty ...