Forum Moderators: open

Message Too Old, No Replies

AJAX from HTTP to HTTPS

         

kristofo

1:56 pm on Mar 30, 2014 (gmt 0)

10+ Year Member



On my page I have the FORM with one INPUT field. On SUBMIT this form I use JavaSript function "test_kod(this)" to valid is the the enetered value correct or not. But in the Internet Explorer ver <=9 the OPEN method allways fall with error "access denied".
WHAT AM I DOING WRONG?
P.S. Because of some limitations I cant use JQUERY.


function test_kod(field) {
var req = createXMLHTTPObject();
if (!req) {
return false;
};
try {
[B]//in IE <= 9 in this place debuger allways return error "access denied"[/B]
req.open("GET","https://dad-atlas.datasolutions.pl/karta.php?karta="+field.value,false);
}
catch(e){
return false;
}
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
return false;
}
if (req.responseText == "TAK") {
return true;
} else {
return false;
};
}
if (req.readyState == 4) return;
req.send();
}

var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}

coopster

7:07 pm on Apr 5, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, kristofo.

It looks like you should be getting a valid object in your "req" variable but have you tried dumping it to the console to be certain?

rainborick

2:25 am on Apr 6, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the protocol (http/https) used to load the page where the AJAX code is executed is not the same as the URL being called by the AJAX function, it's a violation of the same origin policy [en.wikipedia.org]. The exact implementation varies by browser, unfortunately.