Error: Attempted to submit an invalid or unexpected input token

I want to display my ship registration number from the database in an AJAX response. I am using a method to send my field and then show the ship registration number in another function. Here is the code snippet that I have debugged: show_name(2d1c9a7158625608);

<script>
            function show_new_chat(){
                var param_obj = {action: 'voyage/find_all_ship_voyage'}
                var qs = decodeURIComponent($.param(param_obj));
                $.ajax({

                    type: "get",
                    url: 'transport/',
                    data: $(this).serialize() + '&' + qs,
                    dataType: 'json',
                    success:function(res)
                    {
                        var str = '<div>';
                        if (res.data != 0) {
                            $.each(res.data, function(k, v) {
                                str += '<ul>';
                                str += '<button type="button" onclick="show_name('+v.ship_reg_num+');" id="'+v.ship_reg_num+'" style="text-decoration: none; background-color: transparent;" >'+v.ship_name+'</button>';
                                str += '</li>';
                                str += '</ul>';
                                str += '<hr>';
                            });
                        }
                        str +='</div>';
                        $('#list-contact').html(str);
                    },
                    error: function (jqXHR, status, err) {
                        // alert('Local error callback');
                    }
                });
            }
            function show_name(ship_reg_num){

            }
</script>

Answer №1

Don't use $.each function, try using forEach to construct the ui string.

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

What is the best way to retrieve attributes from a through table using a query?

I am in the process of creating a straightforward shopping cart system. My structure includes a Cart model, a Product model, and a connection table called CartItems. Here are the associations: models.Cart.belongsToMany(models.Product, { through: 'Car ...

I am unable to incorporate the RobotJS module into my ElectronJS project

Currently, I am working on a Windows desktop application using ElectronJS. My main challenge is integrating the RobotJS module into my project. Despite successfully downloading the module with 'npm install robotjs' and incorporating it into my ma ...

Setting a default value in an arrow function

Currently, I am working on a section of code that renders a simple loading bar. const smallSpinner = document.getElementById('spinner-small').getContext('2d'); let pointToFill = 4.72; let cw = smallSpinner.canvas.width; //Returns canva ...

Steps to dynamically display or conceal a DIV using Bootstrap 5

I am facing an issue with a navbar that has buttons to reveal hidden divs underneath. <a data-bs-toggle="offcanvas" href="#select" role="button" aria-controls="select"></a> <div id="select" c ...

Creating a new JSON by extracting a specific branch or node from an existing JSON data

I have a Nuki Smartlock and when I make two API calls to the Nuki Bridge, I receive JSON responses. I want to apply the same logic to both responses: When requesting for current states, the JSON looks like this: [{ "deviceType": 0, "nuk ...

A guide on combining two parameters using jQuery in a link for CodeIgniter

I am attempting to pass two parameters through jQuery in the href attribute of an a link, which I will then use in CodeIgniter. Here is my current code: $("#user_comment_show").append("<li>"+...+'<a id="remove_link&qu ...

HMR: The webpack-hot-middleware is not refreshing my webpage

My Vue application, titled hello-world, is utilizing webpack-dev-middleware and webpack-hot-middleware. When running the application, it shows that it's connected in the console. However, after making changes to my main.js file, the following message ...

Unable to establish a hyperlink to specific section of page using MUI 5 Drawer

When attempting to link to a specific part of my first page upon clicking the Shop button in the navigation Drawer, nothing happens: https://i.stack.imgur.com/FUQCp.png This snippet shows the code for the MUI 5 Drawer component: <Drawer anch ...

Using JSP and Ajax to dynamically populate a dropdown menu based on the user's selection

I am currently working on a project where I need to create a dropdown list that will retrieve all product categories from the database and populate them. Another dropdown list should display the product names based on the category selected by the user. Whi ...

jQuery load fails to fill select dropdown

Upon page load, my code executes a call to mysql to populate a select element with data. This process works smoothly on the initial load or when the page is refreshed. However, I am encountering an issue when attempting to update or repopulate the select e ...

three.js canvas, sphere rotates gracefully to the right

Trying to get the sphere to turn right at a very slow pace. Here is my source code: I have created a new container with canvas inside, you can view the code below. How can I make the sphere turn slowly? You can also check out my git repository on github: s ...

Issue: Unable to create the restangular module because: the variable '_' is not defined

Upon integrating Restangular into an existing website, I encountered a JavaScript error that stated: Failed to instantiate module restangular due to: '_' is undefined I'm unsure of what this means. Can anyone clarify why '_' is ...

There seems to be a compatibility issue between AngularJS and HTML

Here is a simple AngularJS code snippet I have written: var app=angular.module("myApp",[]); app.controller("MyController",['$scope',function($scope){ $scope.name="Asim"; $scope.f1=function(){ console.log("i am clicked"); $scope.vr="lol"; } co ...

Plugin for webpack that replaces a specified function with an alternative one

I'm currently working on a webpack plugin that has the ability to analyze code and replace a particular function with another function. Additionally, this plugin will make the new function accessible globally. class PluginName { constructor(local, ...

A step-by-step guide on simulating a click event on an element in React with the help of jest and react-testing

My component displays the following {list.options && list.options.length > 0 ? ( <div data-testId="MyAlertText" onClick={onAddText}> Add Text </div> ) : null} When testing, I am executing the following it('Ensure Add Text lin ...

Using Javascript to efficiently remove elements with AJAX

Currently, I am learning the basics of HTML and focusing on tasks such as login/logout functionality, creating users, and deleting users (only permitted when logged in as an admin). For updating a user password, I have utilized PUT, for creating a user ac ...

The variable continuously updates itself inexplicably, without any specific code dictating it to

In the sandbox-based game I am playing, two variables are present. blocks (this is an array) and blockssave (also an array) However, there are also functions included: var game = { blocksave: function() { blockssave = blocks; blo ...

Changing SVG containing image tags into HTML canvas

I'm attempting to convert an SVG file to an HTML canvas, and everything works perfectly until I introduce the image element in the SVG. When I include image elements, the canvg function stops working. Below is the code I used to convert the SVG to ca ...

Error: JSON parsing encountered an issue with token "o" at position 1 while making an ajax request

When I try to make an AJAX call, my code is set up like this: var Data = { name : $('input[name=name]').val(), email : $('input[name=email]').val(), phoneno : $('input[nam ...

"Enhance Your Phonegap Android App with Pinch Zoom Capability

I am currently working on an Android Application with the help of jQuery Mobile and Phonegap. My goal is to implement pinch zoom functionality on the App pages. I have come across several suggestions that involve using the following line, but unfortunatel ...