I am using Ajax do do cross domain calls using JSON, and the script works fine in FF but in ie the script will not populate the select menu with the results, in ie it will display errors so i know the script is definitely working and making cross domain calls, can anyone tell me what i am doing wrong?
function xss_ajax(url) {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', url);
script.setAttribute('id', 'script_id');
script_id = document.getElementById('script_id');
if (script_id) {
document.getElementsByTagName('head')[0].removeChild(script_id);
}
document.getElementsByTagName('head')[0].appendChild(script);
document.getElementById("addrlist").innerHTML = "";
document.getElementById("errlog").innerHTML = "";
}
function callback(data) {
if (typeof data['error'] != "undefined") {
if (window.on_error) {
on_error();
}
if (document.getElementById("errlog")) {
document.getElementById("errlog").innerHTML = "<br>" + data['error'] + "<br>";
} else {
alert(data['error']);
}
} else {
var val = data['address1'] + ", " + data['address2'] + ", " + data['address3'] + ", " + data['address4'] + ", " + data['postcode'];
document.getElementById("addrlist").innerHTML += "<option value='" + val + "'>" + val + "</option>";
}
}
function searchpost() {
var license = '98798797';
var url = "http://mydomin.co.uk/myfile.php?postcode=" + escape(document.getElementById("field1").value) + '&license=' + escape(license);
xss_ajax(url);
}
I think it is the way that you add the options to the select. Create a new option element and add to the select element instead of replacing all the HTML content: