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

Place the div absolutely on top of the Flash content

Can a <div /> be absolutely positioned over a Flash banner without including wmode="transparent" in the banner? I am trying to display a lightbox above my ads, but I cannot make changes to the banners since they are provided by a third party. Edit: ...

The `Target closed` error in Playwright Library is triggered solely by the closing of either the `context` or `browser`

The code snippet below showcases a Node.js script that leverages the Playwright Library for browser automation (not Playwright Test) to extract data from a local website and display the results in the terminal. The challenge arises when the script encounte ...

Performing an asynchronous POST request in JavaScript

Hey there, I successfully managed to implement a post request using ajax for my submit functionality. However, I am now looking to make this asynchronous to account for any delays in processing by my php file. Unfortunately, I am struggling to figure out h ...

The then() function in Node.js is triggered before the promise is fully resolved

I'm struggling to get my Promise function working as intended. Here's what I need to accomplish: I am receiving file names from stdout, splitting them into lines, and then copying them. Once the copy operation is complete, I want to initiate oth ...

Data update using AJAX and codeigniter was unsuccessful

How can I update my data using Codeigniter and AJAX for submitting the response? Below is the View section of my code: <form id="form_update" action="<?php echo base_url() ?>admin/update_derap_info" method="POST" role="form"> <textare ...

Inadequate speed and efficiency in Javascript and JQuery operations

I'm facing severe lag problems in my JavaScript code, particularly with the parallax effects being very slow. I suspect this is due to multiple executions of functions. Below is the code snippet: function tada() { $(".arrow").addClass("tada"); s ...

"Error: The URL in the Ajax responseText is malfunctioning

My goal is to retrieve data from a MySQL database and display it in a chart. I have two files called index.php and getpiechartdata.php stored on my remote server in the /public_html/ folder. I'm uncertain if the index.php file is actually calling my ...

How can you make each <li> in an HTML list have a unique color?

Looking for a way to assign different colors to each <li> element in HTML? <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <ul> Here's how you want them displayed: Item 1 should be red Ite ...

The Node gracefully disconnects and apologizes: "I'm sorry, but I can't set headers after they have already

events.js:160 throw er; // Unhandled 'error' event ^ Error: Can't set headers after they are sent. register.js:20:18 register.js user.save(function(err) { if(err){ return mainFunctions.sendError(res, req, err, 500, ...

"Exploring the dynamic features of jQuery's mobile listview and

As I work on creating a mobile app using jQuery Mobile, I find myself facing some challenges. Despite my efforts and attempts at different methods, I have not been successful in achieving the desired functionality. Specifically, I am trying to implement a ...

Ajax response values overlap

I am developing an application that requires multiple Ajax requests, but I encountered a problem where I am receiving the same response values for both requests. Each request must include a data field called activityCode, yet I keep getting the value of Sc ...

Display a div element for a specified amount of time every certain number of minutes

I am currently utilizing AngularJS, so whether the solution involves AngularJS or pure JS does not make a difference. In the case of using AngularJS, I have a parameter named isShowDiv which will determine the switching between two divs based on the follow ...

Manipulating data in node.js as it arrives in separate chunks

Hey there, I am trying to make some changes to the data received from the server. All incoming data via the POST method is processed in chunks. <button id='helloButton'>Send hello!</button> <button id='whatsUpButton'>S ...

Problem with Material-UI Drawer

Is there a way to make this drawer stay fixed on the page like a sticker and remain active without moving when scrolling? I've tried using docked={false}, but it makes the whole page inactive except for the drawer. Any suggestions on how to solve this ...

An issue has been identified where the 'connect' event in socket.io does not trigger on the client side

Looking to dive into the world of node.js and socket.io. I've put together a simple client-server test application, but unfortunately it's not functioning as expected. Running the system on a Windows machine with an Apache server setup. Apa ...

Error with declaring TypeScript class due to private variable

When defining a TypeScript class like this: export class myClass { constructor(public aVariable: number) {} private aPrivateVariable: number; } and trying to initialize it with the following code: let someVar: myClass[] = [{ aVariable: 3 }, { aV ...

Turn off the chrome react DevTools when deploying to production to ensure the

I have successfully browserified my react app for production using gulp and envify to set up NODE_ENV. This has allowed me to remove react warnings, error reporting in the console, and even disable some features like the require of react-addons-perf. Afte ...

Sending a JavaScript click event using curl and PHP

Attempting to extract information from a website. The main page contains multiple option buttons along with an ACCEPT and RESET button. When the user selects options and clicks on the ACCEPT button, new content is displayed. I have a question regarding ma ...

Which is the better choice: JSON file or SQL for storing data?

I am in the process of developing a website that will feature an ajax search functionality. This search will retrieve data either from a JSON file or from a MySQL database. I am unsure which technology would be best suited to store this data. With approxim ...

Laravel request pre-loading system

My Laravel application has a search function on the homepage (home.blade.php) that queries the database and displays results on the results page (results.blade.php). Despite using Elastic search to optimize speed, the search still takes around 10 seconds d ...