Issue with an unknown cause (AJAX / GET)

Let's break it down, here's the code I'm working with. It's meant to update the "like" column in my "comments" table. The issue arises when trying to submit the result in JavaScript.

There's a SPAN containing a link to submit:

<span id="like<?=$i?>"><a href="javascript:void()" onClick="likeComment(<?=$row[commentid]?>, <?=$i?>)" />Like</a> (<?=$row[like]?>)</span>

The comment ID is represented by commentid and $i signifies the comment number for updating the correct SPAN tag upon submission of the +Like action.

Next comes the AJAX function that posts to my PHP file:

<script type="text/javascript">
function likeComment(id, no)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("like"+no).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);
xmlhttp.send();
}
</script>

The intention is to send the comment ID and SPAN ID, so the PHP response would be:

<span id="like<?=$number?>"><font color="#009900">You like this</font> (<?=$row[like] + 1?>)</span>

(I omitted the PHP part as the issue doesn't lie there.)

I can't figure out why it's not functioning. It works fine with just one ID, which leads me to suspect either

 xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);

or

document.getElementById("like"+no).innerHTML=xmlhttp.responseText;

In essence, the goal is to submit comment ID 60, for instance, located in SPAN ID'd 5, so on submission, it should return in the right ID.

Any insights are welcome, as I'm at a loss here.

Answer №1

xmlhttp.open("GET","like_game.php?id="+id +"&no="+no,true);

can be rewritten as:

xmlhttp.open("GET","like_game.php?id="+id +"&no="+no,true);

It seems like there was a missing "+" in the original line above :)

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

Tips for troubleshooting the "Vue-Formulate component resolution error"

I am relatively new to working with Vue and I'm finding it challenging. Currently, I am attempting to use Vue-Formulate to create a registration form in my Vue app using Vue 3. Following the official documentation provided by Vue-Formulate, this is ho ...

Rails 5 not allow user submission of bootstrap modal form

I am facing an issue with a form inside a modal in my Rails application. When I click on the submit button, nothing happens. How can I use Ajax to submit the modal form and save its content on another page? <button type="button" class="btn btn-primary ...

The data retrieved by jQuery AJAX is empty when accessed outside of the success handler

Here is a code snippet to consider: let source = null; fetch('https://example.com/data') .then(response => response.json()) .then(data => { source = data; console.log(source); }); console.log(source) When the fetch request ...

Can the jQuery Cycle Plugin: scrollHorz with Prev/Next automatically scroll without any input from the user?

Currently implementing the jQuery cycle plugin: jquery.cycle.all.min.js - newest version (2.8.8) available at http://malsup.com/jquery/cycle/ The scrollHorz effect is being used with previous and next links, functioning perfectly except for one issue: upo ...

Transmitting OfficeJS 2D Array via an Ajax Call

Struggling with sending a "large" table using OfficeJS: functionfile.html loaded from manifest route <script> (function (){ "use strict"; Office.initialize = function (reason) { $(document).ready(function() { $("#send-data-button").cli ...

What are the methods used in TypeScript to implement features that are not available in JavaScript, despite TypeScript ultimately being compiled to JavaScript?

After transitioning from JavaScript to TypeScript, I discovered that TypeScript offers many features not found in JS, such as types. However, TypeScript is ultimately compiled down to JavaScript. How is it possible for a language like TypeScript to achie ...

What is the best way to incorporate bullet points into a textarea?

How can I make a bullet point appear when pressing the 'enter' button inside a textarea? I tried using this code, but it doesn't seem to work. Any suggestions? <script> $(".todolist").focus(function() { if(document.getElementById( ...

Assign a value to the input field based on changes made in another input field

I am brand new to the world of JavaScript and currently grappling with setting a value in an input field based on the onchange event of another input field. Here is my code sample for input field 1: <input type='text' onchange='methodTh ...

Utilizing stream-based reading and writing to execute operations in MySQL database operations

I have extracted data from table tb_project_milestones and aim to insert this projectMilestoneRow into a table tb_xyz using streams. I referred to the documentation, but couldn't figure out how to execute it. Has anyone tried reading and inserting thr ...

Unable to show pop-up upon clicking

My goal is to create a popup that appears when the 'Propose' button is clicked. TestPopUp.tsx const TestPopUp = () => { return ( <div> <p>TEST</p> </div> ); }; export default TestPopUp; CandidateActi ...

Achieve Custom Styling in Material UI Stepper Label with ReactJS: Adjust Font Size and Margin Top

Is there a way to adjust the fontsize of the stepper label and the margin between the label and circle? The default marginTop is set to 16px, but I would like to reduce it. Any suggestions on how to achieve this? Check out the Codesandbox code using Mater ...

What is the best way to retrieve information from an array containing objects in AngularJS?

Check out this json data: { topalbums: { album: [ { name: "The Very Best of Cher", playcount: 1634402, mbid: "a7e2dad7-e733-4bee-9db1-b31e3183eaf5", url: "http://www.last.fm/music/Cher/The+Very+Bes ...

Retrieve the content within a div tag

Hey there, I have a div set up as follows: <div>1+1</div> I'm looking to send this '1+1' value over to my javascript code and calculate it to get '2'. Appreciate any help in advance! ...

How can you create a textbox that initially shows one value but switches to display a different value when clicked?

Is there a way to have a textbox with the default value "enter text here" which changes when clicked on? The current code I have only displays the default value: <input type="text" name="phrase" value="Enter text here..." size="24" onfocus="if(this.va ...

Vue.js - Launching Modal for Editing Data Entry

I have a list of records with corresponding buttons on the right side, as shown in this image: https://i.sstatic.net/uevzR.jpg Whenever I click on one of these buttons, I want a dialog box to appear containing various input fields such as text inputs, dro ...

Error: The "require" function is not recognized within the Rollup bundle JavaScript file

Recently, I've been utilizing rollup to bundle my JavaScript files designed for integration with three.js. It got me thinking about minimizing and bundling the three.js files using rollup.js as well. To achieve this, I used npm and executed the comman ...

Exploring the integration of jquery Datatables within a vue.js framework

As a newcomer to Vue, I've been experimenting with integrating Vue with jquery datatables for a project requirement. However, I have come across some issues while trying to combine the two. Despite my efforts in the code snippets below, I have not bee ...

Displaying 'N/A' in the chart if the data is missing

I have a chart that displays data, but when data does not exist it shows "undefined%". https://i.sstatic.net/Fm3Tl.png Is there a way to remove the "undefined%" and simply display nothing on the graph if no data exists? Here is the code snippet: import { ...

Internet Explorer problem with menu hover

Website: I am encountering an issue with Internet Explorer (9 or lower) where, on hovering over any menu item on the homepage and attempting to select items beyond the first one - for example, hovering over "Shop" and then trying to click on "Brushes" or ...

Function parameter accepting an anonymous value object

While working with prisma nexus and examining the prismaObjectType, I came across something unusual. A simple example of this is as follows: In a basic function, demo(p), the parameter p should be an object. function demo(p) { console.log(p); con ...