S
smorrey
I decided for my first Javascript program, I would port a php currency
conversion utility. However I've come to find out that something
critical was missed during the design phase. That is that
XMLHttpRequest does not function in this circumstance at all, I keep
getting permission denied errors (I'm working in Firefox). Would
someone mind taking a look at the following script and letting me know
if there was maybe a better way, or can this even be done in
Javascript?
Thanx in advance for the help.
function loadXMLDoc(url){
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange(){
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
response = req.responseXML.documentElement.data;
alert("Response was recieved!:\n");
eval(checkRate + '(response)');
} else {
alert("There was a problem retrieving the rate data:\n" +
req.status);
}
}
}
function checkRate(response)
{
alert("checkRate was entered!:\n");
if (response){
// Response mode
alert("Response was not NULL, response is :\n" + response);
if (response == '1'){
message.className = 'error';
}else{
fromprice = document.getElementById('currency_amount').value;
price = fromprice * response;
fromprice.value = price;
}
}else{
// Input mode
fromcur = document.getElementById('currency_from').value;
tocur = document.getElementById('currency_to').value;
url =
'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=l1&s='+fromcur+tocur+'=X';
alert("url is :\n" + url);
loadXMLDoc(url);
}
}
conversion utility. However I've come to find out that something
critical was missed during the design phase. That is that
XMLHttpRequest does not function in this circumstance at all, I keep
getting permission denied errors (I'm working in Firefox). Would
someone mind taking a look at the following script and letting me know
if there was maybe a better way, or can this even be done in
Javascript?
Thanx in advance for the help.
function loadXMLDoc(url){
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange(){
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
response = req.responseXML.documentElement.data;
alert("Response was recieved!:\n");
eval(checkRate + '(response)');
} else {
alert("There was a problem retrieving the rate data:\n" +
req.status);
}
}
}
function checkRate(response)
{
alert("checkRate was entered!:\n");
if (response){
// Response mode
alert("Response was not NULL, response is :\n" + response);
if (response == '1'){
message.className = 'error';
}else{
fromprice = document.getElementById('currency_amount').value;
price = fromprice * response;
fromprice.value = price;
}
}else{
// Input mode
fromcur = document.getElementById('currency_from').value;
tocur = document.getElementById('currency_to').value;
url =
'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=l1&s='+fromcur+tocur+'=X';
alert("url is :\n" + url);
loadXMLDoc(url);
}
}