Unable to use innerHTML function on Blogger platform

I am currently working on a basic voting system. It functions perfectly when the two files are in the same location (locally).

However, once I publish it on my blogger platform, the system fails to display the results. (When a user clicks to vote, it registers on the web host, but the results do not appear!)

Here is the code I am using:

<script type="text/javascript">
function submitVote(int)
{
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("pollResults").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://mypollwebsite.com/vote.php?choice="+int,true);
xmlhttp.send();
}
</script>
<div id="pollResults">
<h3>What do you think?</h3>
<form>
Yes:
<input type="radio" name="vote" value="0" onclick="submitVote(this.value)" />
No:
<input type="radio" name="vote" value="1" onclick="submitVote(this.value)" />
</form>
</div>

Answer №1

Instead of innerHTML being the issue, the problem lies in your attempt to access an external website. Due to a cross-domain restriction implemented in browser protocols, XMLHttpRequest cannot fetch resources from outside your domain.

When the PHP file is hosted on the same domain as the requesting code, it functions properly since there is no cross-domain interaction.

To bypass this restriction, you can employ a proxy script on your domain. This script acts as an intermediary between the page and the external resource, fetching the data from its true location and delivering it back to the browser.

For platforms like Blogger, this solution may not be feasible. In such cases, Blogger offers their own poll widget as an alternative.

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

Determination of an arc trajectory using JavaScript

I have been trying to figure out how to replicate this effect. The Red arrowhead remains stationary while the background features a curved path. Currently, I am adjusting the background position to give the illusion of the arrowhead moving along the curved ...

JavaScript conversion of arrays to JSON data structures

Here is the code snippet along with the variable 'polygon': var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var bermudaTriangle; var directionsPoints; var example; var rez; function initialize() { ...

Loading JavaScript variable with pre-processed JavaScript information

I have been working on loading test data into a javascript object and then passing it to my heating timers. While I have managed to make it work by individually inserting the code into each timer, I am looking to optimize my code and enhance my understandi ...

The concept of IFA on Android and accessing it through the browser/javascript

IFA (Identifier for Advertisers) is a new feature in iOS 6 that functions as a unique ID for tracking user context anonymously and improving the overall experience. My inquiries mainly focus on the realm of web development (specifically mobile browser/jav ...

Exploring the world of unit testing for Sails JS 1.0 helper functions

Currently, I am in the process of setting up unit testing for my SailsJS 1.0 application. My goal is to simulate the DB without needing to execute 'sails lift' to run tests. In my application, there is a straightforward actions2 (node machine) h ...

Utilizing Meta Tags to Enable JavaScript Execution within a Chrome Extension

Introducing my latest creation: Frogga, a Chrome Extension that can be accessed from Frogga on GitHub I've been experimenting with different approaches, but I'm only able to access the initial JSON layer. I have the potential to dig deeper, but ...

Activate an event on a separate webpage using jQuery or JavaScript

Currently, I am in the process of working on a project with 2 distinct pages: Index Settings On the Settings page, I have implemented a button to close an element and hide it. However, I am encountering an issue where I want the elements on the Index pa ...

Elements with v-for directive failing to display

I am attempting to incorporate a component using v-for. The data source infoTexts is structured as an Object where the locale code serves as the key and the corresponding message is the value. For example: { nl: 'Text in Dutch', fr: &apo ...

How can I troubleshoot the 'mdDialog console error' that says 'cannot read property element of null'?

Two of my templates are named Left_template_view_html and center_template_view_html When I click on a md-button in the Left_template_view_html I am attempting to display an mdDialog on the document.body What should I pass into the parent parameter: angu ...

Issue with jqPlot angle setting

I'm having trouble displaying my labels at an angle. Even after attempting to use jqplot.canvasAxisTickRenderer.js as suggested by someone, I keep encountering the following error when I add a reference to it: Uncaught TypeError: Cannot read property ...

Clicking on the mail icon will open the mail with the associated mail id

https://i.sstatic.net/6TLpN.pngWhen the mail icon is clicked, the mail will open with this email address. I am currently working on a project where clicking the mail icon will redirect to the mail signup page with the corresponding email address. In the ...

Filtering arrays of objects dynamically using Typescript

I am looking to create a dynamic filter for an array of objects where I can search every key's value without specifying the key itself. The goal is to return the matched objects, similar to how the angular material table filters all columns. [ { ...

React frontend encountered a connectivity issue while trying to establish a network connection

Our app utilizes next.js connected to express, which is further linked to AWS MySql for database management. While attempting to load some products stored in the database, an error message pops up: TypeError: NetworkError when trying to fetch resource. ...

Having trouble accessing information from Firebase Realtime Database within a React Native application

I am currently developing a React Native application that interacts with a Firebase database for reading and writing data. I have configured my Firebase permissions to allow read and write access: { "rules": { ".read": true, ...

The Kendo Grid is not displaying any data when trying to bind the data source using an ajax callback to the controller

My query is quite similar in nature to this: Binding Kendo Data Source with Async $.ajax calling from C# MVC Controller Action Below is the javascript code used for generating the Kendo grid: $(document).ready(function () { $("#grid").kendo ...

How can we style the <a> link once it has been downloaded?

Is there a way to change the color of a download link after it has been clicked on? I've attempted using the visited attribute, but it only seems to work with regular links and not with download documents: Appreciate any help ...

What is the process of establishing a connection to a web service using Meteor or Node.js?

Currently working on developing a package that interfaces with a web service (either through nodejs or meteor). The web service will be delivering real-time data, so I am in need of a mechanism like a listener or trigger event that can alert me when new da ...

Creating a Cancel Button in JSP/HTML/JS/CSS Form: A Step-by-Step Guide

It is necessary to incorporate the functionality of "save" and "cancel" in the JSP code for this particular form. By selecting "save", the data entered into the form will be submitted to its intended destination. Alternatively, choosing "cancel" will dismi ...

Using JavaScript to Capture a Webpage Element as an Image

Although this question has been asked in the past, I am hoping for updated information since all the answers are from a few years ago. While searching, I came across https://github.com/apollolm/phantasm, which seems to be exactly what I need. However, it ...

What is the best way to implement vuelidate when dealing with an array of objects?

In my form questionnaire, I am looping through an array of objects. Each object has five properties, but only one property needs validation. The validation setup in the component looks like this: specificGifts: { $each: { passThrough: { ...