尝试使用油脂猴脚本使用我们数据库中的数据在客户网站上预填充表单,但我无法弄清楚如何绕过同源策略。
我正在使用GM_xmlhttpRequest甚至指定@grant GM_xmlhttpRequest但没有运气..
这是我的脚本我做错了什么?
// ==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*nnName: "+fnamect+" "+lnamect+"nAddress: "+addrct+"nCity: "+cityct+"nState: "+statect+"nZip: "+zipct+"nEmail: "+emailct+"nnClick '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);
您正在使用xmlhttpp
但它没有在任何地方定义。 您需要在 response
上解析。 看到这个答案。