GM Unable to Establish Cross-Domain Ajax Connection

Attempting to populate a form on a client's website with data from our database using a Greasemonkey script, but struggling with the same origin policy.

I have tried using GM_xmlhttpRequest and even specified @grant GM_xmlhttpRequest but without success.

Here is my script. What am I missing?

// ==UserScript==
// @name        ORL Prepop Test
// @namespace   customertrackinc.com
// @description Prepopulate ORL Fields
// @include     https://www.openroadlending.com/Apply.aspx*
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==

document.body.style.background = "white";
document.getElementById('ctl00_TopMenu_T872C6B14002_Menu1').innerHTML = "";
document.getElementById('Header').style.background = "#968888";
document.getElementById('Header').style.color = "black";
document.getElementById('Header').style.backgroundRepeat = "no-repeat";
document.getElementById('Header').style.backgroundPosition="bottom left"; 
document.getElementById('Header').style.border = "1px solid black";
document.getElementById('Header').style.padding = "1em";
document.getElementById('SuperLinks').innerHTML = "";
document.getElementById('SideBar').innerHTML = "";
document.getElementById('Logo').innerHTML = "";
document.getElementById('TagLine').innerHTML = "";
document.getElementById('LP_DIV_1368197056862').style.display = "none";
document.getElementById('Header').innerHTML =  '<div style="position:absolute; bottom:0; left:0; padding:.5em;">Script is working so far...</div>';


var boxes = document.getElementsByClassName('sfContentBlock'),
i = boxes.length;
while(i--) {
    boxes[i].style.display = "none;";
}

var all=document.getElementsByTagName("h1");
for (var i=0, max=all.length; i < max; i++) {
    all[i].style.display = "none";
}

var all=document.getElementsByTagName("h2");
for (var i=0, max=all.length; i < max; i++) {
    all[i].style.display = "none";
}

function addEventHandler(elem,eventType,handler) {
 if (elem.addEventListener)
     elem.addEventListener (eventType,handler,false);
 else if (elem.attachEvent)
     elem.attachEvent ('on'+eventType,handler); 
}

function startAjax(){
    var param1ct = document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1').value;
    var param2ct = document.getElementById('BodyContent_ctl00_ctl00_txtLastName1').value;
    var param3ct = document.getElementById('BodyContent_ctl00_ctl00_txtStreetAddress1').value;
    var urlct = "URL INTENTIONALLY OMITTED/ajaxhandler.php?fname="+param1ct+"&lname"+param2ct+"&addr"+param3ct;
    GM_xmlhttpRequest({
        method: "GET",
        url: urlct,
        onload: function(response) {
            var statusct = xmlhttpp.responseXML.getElementsByTagName('status')[0].firstChild.nodeValue;
            var fnamect = xmlhttpp.responseXML.getElementsByTagName('fname')[0].firstChild.nodeValue;
            var addrct = xmlhttpp.responseXML.getElementsByTagName('addr')[0].firstChild.nodeValue;
            var lnamect = xmlhttpp.responseXML.getElementsByTagName('lname')[0].firstChild.nodeValue;
            var cityct = xmlhttpp.responseXML.getElementsByTagName('city')[0].firstChild.nodeValue;
            var statect = xmlhttpp.responseXML.getElementsByTagName('street')[0].firstChild.nodeValue;
            var zipct = xmlhttpp.responseXML.getElementsByTagName('zip')[0].firstChild.nodeValue;
            var emailct = xmlhttpp.responseXML.getElementsByTagName('email')[0].firstChild.nodeValue;

            document.getElementById("Header").innerHTML=statusct;
            if(status == "Bingo"){
                var confirmMsg = "*User Found*\n\nName: "+fnamect+" "+lnamect+"\nAddress: "+addrct+"\nCity: "+cityct+"\nState: "+statect+"\nZip: "+zipct+"\nEmail: "+emailct+"\n\nClick 'OK' To populate fields or click 'Cancel' if this is not the correct info.";
                var fillOrNot = confirm(confirmMsg);
                if(fillOrNot === true){                     
                    document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1').value = fnamect;
                    document.getElementById('BodyContent_ctl00_ctl00_txtLastName1').value = lnamect;
                    document.getElementById('BodyContent_ctl00_ctl00_txtStreetAddress1').value = addrct;
                }else{
                    document.getElementById("Header").innerHTML="Aborted";
                }
            }
        }
    });
}

var first_name_field = document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1');
addEventHandler(first_name_field,"keyup",startAjax);

Answer №1

There seems to be an issue with the xmlhttpp variable as it is not declared anywhere in your code. Make sure to properly parse the response object. For more information, refer to this specific answer.

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

The View Component is experiencing issues with loading the CSS and JS files correctly when an AJAX call is made

Hey there! I'm having trouble loading a view component via ajax when the button is clicked. It seems like the css and javascript are not working properly. Check out the ajax call for the controller to load the component: $.ajax({ url: window.locat ...

Using ng-transclude directive allows for encapsulating HTML content within an ng-transclude element

My directive includes an ng-repeat in the template and also has an ng-transclude option after the repeater to allow users to input their own content. The issue arises when the custom content is surrounded by an ng-transclude element upon rendering, which i ...

What is the reason for IE displaying null when the model does not exist?

Why does IE 11 render 'null' if my model does not exist? For instance: <tr> <td [innerHTML]="model?.prop1 | my-pipe"></td> </tr> Imagine this scenario: When the page loads, a request is sent to the server and the res ...

Obtain the number of elements rendered in a React parent component from a switch or route

I'm currently working on a component that is responsible for rendering wrapper elements around its children. One challenge I'm facing is determining which elements are actually being rendered as children. I've implemented functions to ignore ...

The process of converting a response into an Excel file

After sending a request to the server and receiving a response, I am struggling with converting this response into an Excel file. Response header: Connection →keep-alive cache-control →no-cache, no-store, max-age=0, must-revalidate content-dispositio ...

Troubleshooting NPM installation failures with SQLite build

After updating to macOS Mojave and installing the latest versions of node 12.1.0, npm 6.9.0, brew 2.1.1, and Python 2.7.10 on darwin, I encountered an issue while running npm install in a package.json file for a project that includes "sqlite3": "4.0.6". ...

Generate an HTML document from a website page

Having difficulty grasping this concept. I am completely lost on where to begin. It is imperative that I determine how my website can generate a file (whether it be HTML or Text format) and enable users to download it, similar to the functionality in Goo ...

Deciding whether an array forms a chain of factors

I am curious about the reasons why this code is failing some of the tests provided. It deliberately avoids using any ES6 code. Here is the given prompt: *A factor chain can be defined as an array where each preceding element serves as a factor for the su ...

How can I retrieve and showcase the size of each file, including images, CSS, and JS, present on a website?

Currently, my goal is to create a dashboard capable of retrieving the file size for all resources (images, javascript, css, etc.) loaded on a webpage. I aim to then further filter these resources by file type and file size in order to identify which ones c ...

A JSON request is being processed within a while loop

Attempting to complete what I initially thought was a simple task has led me to believe that I may have oversimplified the process or made a mistake in my loop. My objective is to browse through a series of links containing JSON objects in order to identif ...

The Backbone.js template does not automatically inherit attributes from the model

Hey there, I'm currently working on setting up a simple SPA using Backbone for testing purposes. However, when I try to render my view, the Underscore template doesn't seem to be picking up any attributes from my model. I've been trying to t ...

In Node.js, JavaScript, when using SQLite, the variables are inserted as Null

I have spent a lot of time searching and trying various methods, but I am still unable to solve this issue. My goal is to insert 8 variables received from an API call into an SQLite table. Although the execution seems correct, when I query the table, all v ...

Utilizing the invoke() method within the each() function in Cypress to access the href attribute

I recently started using Cypress and I'm attempting to retrieve the href attribute for each div tag within a group by utilizing invoke(), however, it is resulting in an error. Could anyone provide guidance on the correct way to achieve this? cy.get(&a ...

Firing two events simultaneously with a single click using jQuery Ajax

I have limited knowledge of jquery ajax and I am attempting to trigger 2 events simultaneously with a single click. However, it doesn't seem to be working for me and I'm not sure where the issue lies. $(document).ready(function() { $("#trigg ...

Encountering Axios CanceledError while attempting to forward a POST request using Axios

While attempting to relay a POST request from an express backend to another backend using axios, I encountered an axios error stating "CanceledError: Request stream has been aborted". Interestingly, this issue does not arise when dealing with GET requests. ...

Issue: Unable to access API target map in AGM using Google Map API

I attempted to integrate a Google map with multiple locations. While I was successful in using an Iframe for one location, I struggled to implement multiple locations within the Iframe. As a result, I tried utilizing AGM and used the same APIKey that I ha ...

Delivering objects from controller in AngularJS

I'm currently working on a project where I need to retrieve objects from the controller. Here's a snippet of my code: score.component.js: angular.module('score').component('score',{ templateUrl : 'app/score/score.t ...

Obtain the origin of the image using dots in Javascript

Sharing my experience with setting a background image using Javascript. Initially, I tried using two dots like this: .style.backgroundImage = "url('../images/image00.jpg')" However, it did not work as expected. So, I removed one dot: .style.ba ...

Converting the 'require' call to an import may be a more efficient method when importing package.json in a typescript file

In my current project, I am creating a class where I am directly accessing the package version number like this: const pkg = require('../package.json') export class MyClass() { constructor() { // Set the base version from package.jso ...

What are some solutions for resolving the issue of a neutralino white screen?

After setting up a new neutralino js application, I encountered an issue where upon running it with the 'neu run' command, all I see is a blank white screen. I tried using the CheckNetIsolation.exe ... command to troubleshoot the problem, but unf ...