javascript xmlhttp.open("GET", url, true)
Posted: Tue Jan 16, 2018 10:24 am
I have created a service program that is called using PHP. The service program is an SQLRPGLE that returns a result set. This allows me to created a java script function for an OnChange event. I have created it using XML and JSON. When the XML and JSON is stored in a folder "/profoundui/userdata/xml/cust.xml" I get a result set returned. The issue I am having is when I build a URL interactively I do not get a connection. I have a field called "Cust" and on called "Item" that is used when building the URL. When the URL is put a browser I get a result. I looked at your AJAX api's but we can't figure out how to use them.
we would like to use a URL like -
var Item = document.getElementById('Item').value;
var Cust = document.getElementById('Cust').value;
var ItmQty = 1;
var url = "http://rdcportal/getcost.php?item=" + Item + "&cust=" + Cust + "&qty=" + ItmQty;
Below are the JavaScripts -
-----------------------------------------------------------------------------------------------------------------------------------
// OnChange -
function getPrice(){
var xmlhttp = new XMLHttpRequest();
var url = "/profoundui/userdata/xml/pcr0080.txt";
xmlhttp.onreadystatechange = function() {
if ((this.readyState == 4 && this.status == 200)) {
var xmr = JSON.parse(this.responseText);
document.getElementById("ItemCost").innerHTML = xmr.$COST;
document.getElementById("Method").innerHTML = xmr["@COST_MTHD"];
var c = JSON.stringify(xmr.$COST);
alert("c = " + c);
changeElementValue( "Cost", c );
var m = JSON.stringify(xmr["@COST_MTHD"]);
alert("m = " + m);
changeElementValue( "Meth", m );
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
getPrice();
-----------------------------------------------------------------------------------------------------------------------------------
--- OR ---
// OnChange -
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "/profoundui/userdata/xml/cust.xml", true);
xhttp.send();
}
function myFunction(xml) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("cost")[0];
y = x.childNodes[0];
c = y.nodeValue;
changeElementValue( "Cost", c );
x = xmlDoc.getElementsByTagName("cost_mthd")[0];
y = x.childNodes[0];
m = y.nodeValue;
changeElementValue( "Meth", m );
}
loadDoc();
-----------------------------------------
FYI this works - but is not useful
var Item = document.getElementById('Item').value;
var Cust = document.getElementById('Cust').value;
var ItmQty = 1;
var url = "http://rdcportal/getcost.php?item=" + Item + "&cust=" + Cust + "&qty=" + ItmQty;
postToNewWindow(url);
we would like to use a URL like -
var Item = document.getElementById('Item').value;
var Cust = document.getElementById('Cust').value;
var ItmQty = 1;
var url = "http://rdcportal/getcost.php?item=" + Item + "&cust=" + Cust + "&qty=" + ItmQty;
Below are the JavaScripts -
-----------------------------------------------------------------------------------------------------------------------------------
// OnChange -
function getPrice(){
var xmlhttp = new XMLHttpRequest();
var url = "/profoundui/userdata/xml/pcr0080.txt";
xmlhttp.onreadystatechange = function() {
if ((this.readyState == 4 && this.status == 200)) {
var xmr = JSON.parse(this.responseText);
document.getElementById("ItemCost").innerHTML = xmr.$COST;
document.getElementById("Method").innerHTML = xmr["@COST_MTHD"];
var c = JSON.stringify(xmr.$COST);
alert("c = " + c);
changeElementValue( "Cost", c );
var m = JSON.stringify(xmr["@COST_MTHD"]);
alert("m = " + m);
changeElementValue( "Meth", m );
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
getPrice();
-----------------------------------------------------------------------------------------------------------------------------------
--- OR ---
// OnChange -
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "/profoundui/userdata/xml/cust.xml", true);
xhttp.send();
}
function myFunction(xml) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("cost")[0];
y = x.childNodes[0];
c = y.nodeValue;
changeElementValue( "Cost", c );
x = xmlDoc.getElementsByTagName("cost_mthd")[0];
y = x.childNodes[0];
m = y.nodeValue;
changeElementValue( "Meth", m );
}
loadDoc();
-----------------------------------------
FYI this works - but is not useful
var Item = document.getElementById('Item').value;
var Cust = document.getElementById('Cust').value;
var ItmQty = 1;
var url = "http://rdcportal/getcost.php?item=" + Item + "&cust=" + Cust + "&qty=" + ItmQty;
postToNewWindow(url);