I have make cookies in java script page but when used in the Controller page it shows null and i Check in the browser cookies is also created so please help me for this ......
<script>
#Html.Raw(ViewBag.CallJSFuncOnPageLoad)
function IPDetction()
{
$.getJSON("http://ip-api.com/json/?callback=?", function (data) {
var items = [];
$.each(data, function (key, val)
{
if (key == 'city') {
document.cookie = "DetectedCityName=" + val;
}
if (key == 'region') {
document.cookie = "DetectedRegionName=" + val;
}
});
});
}
</script>
#{
string DetectedCityName = "Toronto";
try
{
RateMadnessfinal.DataModel.RateMadnessdbEntities db = new RateMadnessfinal.DataModel.RateMadnessdbEntities();
DetectedCityName = HttpContext.Current.Request.Cookies["DetectedCityName"].Value;
var getCityID = db.Macities.Where(c => c.CityName.Contains(DetectedCityName)).ToList();
if ((getCityID != null) && (getCityID.Count > 0))
{
DetectedCityName = getCityID.FirstOrDefault().CityName;
}
else
{
DetectedCityName = "Toronto";
}
}
catch (Exception e)
{
DetectedCityName = "Toronto";
}
}
Related
I'm in way over my head here and need some help to understand what I'm looking at please! (Very new to Javascript!) Here is the situation as I understand it...
I have a script that is selecting a single line from a paragraph of text, and currently produces this alert, where '1' is the selected line:
alert(getLine("sourcePara", 1));
...Instead of triggering an alert I need this selected text to feed into this separate script which is sending data to another browser window. Presently it's taking a text field from a form with the id 'STOCK1', but that can be replaced:
function sendLog() {
var msg = document.getElementById('STOCK1').value;
t.send('STK1', msg);
}
I'm totally confused as to what form this text data is taking on the way out of the first script and have no idea how to call it in as the source for the second... HELP!
All the thanks!
EDIT:
Here is the source code for the Local Connection element;
function LocalConnection(options) {
this.name = 'localconnection';
this.id = new Date().getTime();
this.useLocalStorage = false;
this.debug = false;
this._actions= [];
this.init = function(options) {
try {
localStorage.setItem(this.id, this.id);
localStorage.removeItem(this.id);
this.useLocalStorage = true;
} catch(e) {
this.useLocalStorage = false;
}
for (var o in options) {
this[o] = options[o];
}
this.clear();
}
this.listen = function() {
if (this.useLocalStorage) {
if (window.addEventListener) {
window.addEventListener('storage', this.bind(this, this._check), false);
} else {
window.attachEvent('onstorage', this.bind(this, this._check));
}
} else {
setInterval(this.bind(this, this._check), 100);
}
}
this.send = function(event) {
var args = Array.prototype.slice.call(arguments, 1);
return this._write(event, args);
}
this.addCallback = function(event, func, scope) {
if (scope == undefined) {
scope = this;
}
if (this._actions[event] == undefined) {
this._actions[event] = [];
}
this._actions[event].push({f: func, s: scope});
}
this.removeCallback = function(event) {
for (var e in this._actions) {
if (e == event) {
delete this._actions[e];
break;
}
}
}
this._check = function() {
var data = this._read();
if (data.length > 0) {
for (var e in data) {
this._receive(data[e].event, data[e].args);
}
}
}
this._receive = function(event, args) {
if (this._actions[event] != undefined) {
for (var func in this._actions[event]) {
if (this._actions[event].hasOwnProperty(func)) {
this.log('Triggering callback "'+event+'"', this._actions[event]);
var callback = this._actions[event][func];
callback.f.apply(callback.s, args);
}
}
}
};
this._write = function(event, args) {
var events = this._getEvents();
var evt = {
id: this.id,
event: event,
args: args
};
events.push(evt);
this.log('Sending event', evt);
if (this.useLocalStorage) {
localStorage.setItem(this.name, JSON.stringify(events));
} else {
document.cookie = this.name + '=' + JSON.stringify(events) + "; path=/";
}
return true;
}
this._read = function() {
var events = this._getEvents();
if (events == '') {
return false;
}
var ret = [];
for (var e in events) {
if (events[e].id != this.id) {
ret.push({
event: events[e].event,
args: events[e].args
});
events.splice(e, 1);
}
}
if (this.useLocalStorage) {
localStorage.setItem(this.name, JSON.stringify(events));
} else {
document.cookie = this.name + '=' + JSON.stringify(events) + "; path=/";
}
return ret;
}
this._getEvents = function() {
return this.useLocalStorage ? this._getLocalStorage() : this._getCookie();
}
this._getLocalStorage = function() {
var events = localStorage.getItem(this.name);
if (events == null) {
return [];
}
return JSON.parse(events);
}
this._getCookie = function() {
var ca = document.cookie.split(';');
var data;
for (var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(this.name+'=') == 0) {
data = c.substring(this.name.length+1, c.length);
break;
}
}
data = data || '[]';
return JSON.parse(data);
}
this.clear = function() {
if (this.useLocalStorage) {
localStorage.removeItem(this.name);
} else {
document.cookie = this.name + "=; path=/";
}
}
this.bind = function(scope, fn) {
return function () {
fn.apply(scope, arguments);
};
}
this.log = function() {
if (!this.debug) {
return;
}
if (console) {
console.log(Array.prototype.slice.call(arguments));
}
}
this.init(options);
}
If I understand what you are asking for correctly, then I think its a matter of changing your log function to the following:
function sendLog() {
t.send('STK1', getLine("sourcePara", 1));
}
This assumes that getLine is globally accessible.
Alternatively Another approach would be to allow for the sendLog function to take the message as a parameter. In which case, you would change your first script to be:
sendLog(getLine("sourcePara", 1));
And the modified sendLog function would look like this:
function sendLog(msg) {
t.send('STK1', msg);
}
LocalConnection.js should handle transferring the data between windows/tabs. Looks like an an iteresting project:
https://github.com/jeremyharris/LocalConnection.js
I am using sessionStorage to get some data and able to use it to create a link and append it to the page.
(function() {
var rep_info = document.getElementById('rep-info'),
session = sessionStorage.getItem('ngStorage-getRepInfo'),
obj = JSON.parse(session),
vanity_name = obj.profile.data.vanityName,
your_URL = 'https://foo.com/';
console.log(obj.profile.data.vanityName);
rep_info.insertAdjacentHTML('afterbegin', 'foo.com/' + vanity_name + '');
})();
However if I copy and paste the URL of the page which contains the script above, it doesn't fire. Instead I get this error.
Uncaught TypeError: Cannot read property 'profile' of null
But when I do a refresh, the script fires.
I should mention this page/site is accessed via user authentification i.e. username & password.
I found this solution, but I couldn't figure out how to get it going.
Thanks in advance!
UPDATE 2-1-2017
I included the library I referenced and my attempt at using to solve my problem, it's right after the module.
var LocalStoreManager = (function() {
function LocalStoreManager() {
var _this = this;
this.syncKeys = [];
this.reservedKeys = ['sync_keys', 'addToSyncKeys', 'removeFromSyncKeys',
'getSessionStorage', 'setSessionStorage', 'addToSessionStorage', 'removeFromSessionStorage', 'clearAllSessionsStorage', 'raiseDBEvent'
];
this.sessionStorageTransferHandler = function(event) {
if (!event.newValue)
return;
if (event.key == 'getSessionStorage') {
if (sessionStorage.length) {
localStorage.setItem('setSessionStorage', JSON.stringify(sessionStorage));
localStorage.removeItem('setSessionStorage');
}
} else if (event.key == 'setSessionStorage') {
if (!_this.syncKeys.length)
_this.loadSyncKeys();
var data = JSON.parse(event.newValue);
for (var key in data) {
if (_this.syncKeysContains(key))
sessionStorage.setItem(key, data[key]);
}
} else if (event.key == 'addToSessionStorage') {
var data = JSON.parse(event.newValue);
_this.addToSessionStorageHelper(data["data"], data["key"]);
} else if (event.key == 'removeFromSessionStorage') {
_this.removeFromSessionStorageHelper(event.newValue);
} else if (event.key == 'clearAllSessionsStorage' && sessionStorage.length) {
_this.clearInstanceSessionStorage();
} else if (event.key == 'addToSyncKeys') {
_this.addToSyncKeysHelper(event.newValue);
} else if (event.key == 'removeFromSyncKeys') {
_this.removeFromSyncKeysHelper(event.newValue);
}
};
}
//Todo: Implement EventListeners for the various event operations and a SessionStorageEvent for specific data keys
LocalStoreManager.prototype.initialiseStorageSyncListener = function() {
if (LocalStoreManager.syncListenerInitialised == true)
return;
LocalStoreManager.syncListenerInitialised = true;
window.addEventListener("storage", this.sessionStorageTransferHandler, false);
this.syncSessionStorage();
};
LocalStoreManager.prototype.deinitialiseStorageSyncListener = function() {
window.removeEventListener("storage", this.sessionStorageTransferHandler, false);
LocalStoreManager.syncListenerInitialised = false;
};
LocalStoreManager.prototype.syncSessionStorage = function() {
localStorage.setItem('getSessionStorage', '_dummy');
localStorage.removeItem('getSessionStorage');
};
LocalStoreManager.prototype.clearAllStorage = function() {
this.clearAllSessionsStorage();
this.clearLocalStorage();
};
LocalStoreManager.prototype.clearAllSessionsStorage = function() {
this.clearInstanceSessionStorage();
localStorage.removeItem(LocalStoreManager.DBKEY_SYNC_KEYS);
localStorage.setItem('clearAllSessionsStorage', '_dummy');
localStorage.removeItem('clearAllSessionsStorage');
};
LocalStoreManager.prototype.clearInstanceSessionStorage = function() {
sessionStorage.clear();
this.syncKeys = [];
};
LocalStoreManager.prototype.clearLocalStorage = function() {
localStorage.clear();
};
LocalStoreManager.prototype.addToSessionStorage = function(data, key) {
this.addToSessionStorageHelper(data, key);
this.addToSyncKeysBackup(key);
localStorage.setItem('addToSessionStorage', JSON.stringify({ key: key, data: data }));
localStorage.removeItem('addToSessionStorage');
};
LocalStoreManager.prototype.addToSessionStorageHelper = function(data, key) {
this.addToSyncKeysHelper(key);
sessionStorage.setItem(key, data);
};
LocalStoreManager.prototype.removeFromSessionStorage = function(keyToRemove) {
this.removeFromSessionStorageHelper(keyToRemove);
this.removeFromSyncKeysBackup(keyToRemove);
localStorage.setItem('removeFromSessionStorage', keyToRemove);
localStorage.removeItem('removeFromSessionStorage');
};
LocalStoreManager.prototype.removeFromSessionStorageHelper = function(keyToRemove) {
sessionStorage.removeItem(keyToRemove);
this.removeFromSyncKeysHelper(keyToRemove);
};
LocalStoreManager.prototype.testForInvalidKeys = function(key) {
if (!key)
throw new Error("key cannot be empty");
if (this.reservedKeys.some(function(x) {
return x == key;
}))
throw new Error("The storage key \"" + key + "\" is reserved and cannot be used. Please use a different key");
};
LocalStoreManager.prototype.syncKeysContains = function(key) {
return this.syncKeys.some(function(x) {
return x == key;
});
};
LocalStoreManager.prototype.loadSyncKeys = function() {
if (this.syncKeys.length)
return;
this.syncKeys = this.getSyncKeysFromStorage();
};
LocalStoreManager.prototype.getSyncKeysFromStorage = function(defaultValue) {
if (defaultValue === void 0) { defaultValue = []; }
var data = localStorage.getItem(LocalStoreManager.DBKEY_SYNC_KEYS);
if (data == null)
return defaultValue;
else
return JSON.parse(data);
};
LocalStoreManager.prototype.addToSyncKeys = function(key) {
this.addToSyncKeysHelper(key);
this.addToSyncKeysBackup(key);
localStorage.setItem('addToSyncKeys', key);
localStorage.removeItem('addToSyncKeys');
};
LocalStoreManager.prototype.addToSyncKeysBackup = function(key) {
var storedSyncKeys = this.getSyncKeysFromStorage();
if (!storedSyncKeys.some(function(x) {
return x == key;
})) {
storedSyncKeys.push(key);
localStorage.setItem(LocalStoreManager.DBKEY_SYNC_KEYS, JSON.stringify(storedSyncKeys));
}
};
LocalStoreManager.prototype.removeFromSyncKeysBackup = function(key) {
var storedSyncKeys = this.getSyncKeysFromStorage();
var index = storedSyncKeys.indexOf(key);
if (index > -1) {
storedSyncKeys.splice(index, 1);
localStorage.setItem(LocalStoreManager.DBKEY_SYNC_KEYS, JSON.stringify(storedSyncKeys));
}
};
LocalStoreManager.prototype.addToSyncKeysHelper = function(key) {
if (!this.syncKeysContains(key))
this.syncKeys.push(key);
};
LocalStoreManager.prototype.removeFromSyncKeys = function(key) {
this.removeFromSyncKeysHelper(key);
this.removeFromSyncKeysBackup(key);
localStorage.setItem('removeFromSyncKeys', key);
localStorage.removeItem('removeFromSyncKeys');
};
LocalStoreManager.prototype.removeFromSyncKeysHelper = function(key) {
var index = this.syncKeys.indexOf(key);
if (index > -1) {
this.syncKeys.splice(index, 1);
}
};
LocalStoreManager.prototype.saveSessionData = function(data, key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
this.removeFromSyncKeys(key);
localStorage.removeItem(key);
sessionStorage.setItem(key, data);
};
LocalStoreManager.prototype.saveSyncedSessionData = function(data, key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
localStorage.removeItem(key);
this.addToSessionStorage(data, key);
};
LocalStoreManager.prototype.savePermanentData = function(data, key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
this.removeFromSessionStorage(key);
localStorage.setItem(key, data);
};
LocalStoreManager.prototype.moveDataToSessionStorage = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
var data = this.getData(key);
if (data == null)
return;
this.saveSessionData(data, key);
};
LocalStoreManager.prototype.moveDataToSyncedSessionStorage = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
var data = this.getData(key);
if (data == null)
return;
this.saveSyncedSessionData(data, key);
};
LocalStoreManager.prototype.moveDataToPermanentStorage = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
var data = this.getData(key);
if (data == null)
return;
this.savePermanentData(data, key);
};
LocalStoreManager.prototype.getData = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
var data = sessionStorage.getItem(key);
if (data == null)
data = localStorage.getItem(key);
return data;
};
LocalStoreManager.prototype.getDataObject = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
var data = this.getData(key);
if (data != null)
return JSON.parse(data);
else
return null;
};
LocalStoreManager.prototype.deleteData = function(key) {
if (key === void 0) { key = LocalStoreManager.DBKEY_USER_DATA; }
this.testForInvalidKeys(key);
this.removeFromSessionStorage(key);
localStorage.removeItem(key);
};
return LocalStoreManager;
})();
(function() {
var localStorageMangerInstance = new LocalStoreManager();
localStorageMangerInstance.initialiseStorageSyncListener();
var data = localStorageMangerInstance.getData('ngStorage-getRepInfo'),
obj = JSON.parse(data),
vanity_name = obj.profile.data.vanityName;
localStorageMangerInstance.saveSyncedSessionData(obj, obj.profile.data.vanityName);
var rep_info = document.getElementById('rep-info'),
your_avon_URL = 'https://youravon.com/';
rep_info.insertAdjacentHTML('afterbegin', 'youravon.com/' + vanity_name + '');
console.log(vanity_name);
console.log(obj.profile.data.vanityName);
})();
I have created a Javascript function to make SignalR even more magical:
//Initializable
function Initializable(params) {
this.initialize = function (key, def, private) {
if (def !== undefined) {
(!!private ? params : this)[key] = (params[key] !== undefined) ? params[key] : def;
}
};
}
/*SignalR Updater*/
function SignalRUpdater(params) {
Initializable.call(this, params);
var self = this;
this.initialize("RawHubs", [], true);
this.initialize("RawGroups", {}, true);
this.initialize("Connection", $.connection, true);
this.initialize("Extend", {});
this.Hubs = {};
this.addHub = function (name, extend) {
if (self.Hubs[name]) {
return false;
}
self.Hubs[name] = params.Connection[name];
self.Hubs[name].Groups = {};
params.RawHubs.push(name);
if (!params.RawGroups[name]) {
params.RawGroups[name] = [];
}
if (extend) {
if ((!self.Extend) || (!extend.append)) {
self.Extend = extend;
} else {
if (!self.Extend) {
self.Extend = {};
}
if (extend.append) {
for (var extendIndex in extend) {
if (extendIndex !== "append") {
self.Extend = extend[extendIndex];
}
}
} else {
self.Extend = extend;
}
}
$.extend(params.Connection[name].client, self.Extend);
} else if (self.Extend) {
$.extend(params.Connection[name].client, self.Extend);
}
return true;
};
this.removeHub = function (name) {
if (!self.Hubs[name]) {
return false;
}
for (var groupIndex in self.Hubs[name].Groups) {
self.Hubs[name].Groups[groupIndex].unsubscribe();
}
delete self.Hubs[name];
delete params.RawGroups[name];
params.RawHubs.splice(params.RawHubs.indexOf(name), 1);
return true;
};
this.addGroupToHub = function (hubName, groupName) {
if ((self.Hubs[hubName]) && (self.Hubs[hubName].Groups[groupName])) {
return false;
}
self.Hubs[hubName].server.subscribe(groupName);
self.Hubs[hubName].Groups[groupName] = {}; //Here we can hold group-related data
if (params.RawGroups[hubName].indexOf(groupName) < 0) {
params.RawGroups[hubName].push(groupName);
}
return true;
};
this.removeGroupFromHub = function (hubName, groupName) {
if ((!self.Hubs[hubName]) || (!self.Hubs[hubName].Groups[groupName])) {
return false;
}
self.Hubs[hubName].server.unsubscribe(groupName);
delete self.Hubs[hubName].Groups[groupName];
if (params.RawGroups[hubName].indexOf(groupName) >= 0) {
params.RawGroups[hubName].splice(params.RawGroups[hubName].indexOf(groupName), 1);
}
return true;
};
for (var hubIndex in params.RawHubs) {
self.addHub(params.RawHubs[hubIndex]);
}
params.Connection.hub.start().done(function () {
for (var hubIndex in params.RawGroups) {
for (var groupIndex in params.RawGroups[hubIndex]) {
self.addGroupToHub(hubIndex, params.RawGroups[hubIndex][groupIndex]);
}
}
});
}
I am using it like this, for example:
function statusUpdate(status) {
alert(status);
}
var signalRUpdater = new SignalRUpdater({
RawHubs: ["statusUpdates"],
Extend: {
statusUpdate: statusUpdate
}
});
So far, so good. However, I may have several groups in the same hub and at the point of statusUpdate I do not seem to know about the group. I can send it from server-side as a parameter to statusUpdate, but I wonder whether this is an overkill and whether it is possible out of the box with SignalR.
When sending a group message to clients the server does not send the name of the group the message was sent to. The server selects clients that are members of the group and just sends them the message. If you want to understand the protocol SignalR is using you can find a description I wrote some time ago here.
I'm trying to get the local ressources key from .rsex file in javascript, but it doesn't work, I got error "not available".
Thanks for your help.
var key = "errMesgLength"
var val = eval('<%= GetLocalResourceObject("' + key + '") %>');
lblMessage.innerHTML = val;
Thank you Michael for help.
I have found a solution.
In C# code I have used a web method
[WebMethod()]
public static string GetLocalRessources(string key)
{
var currentLanguage = (Language)HttpContext.Current.Session["CurrentLanguage"];
if (currentLanguage == Language.French)
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
}
else
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}
return HttpContext.GetLocalResourceObject("~/SelfRegistration.aspx", key, Thread.CurrentThread.CurrentCulture).ToString();
}
and in JS code, I have used PageMethos call
function IsIMEI() {
var imei = document.querySelector(".txt-imei");
var lblMessage = document.querySelector(".lblMsgError");
var key;
if (imei) {
if (imei.value !== "IMEI / Serial Number") {
if (imei.value.toString().length > 7) {
imei.style.border = "";
lblMessage.innerHTML = "";
return true;
}
else {
key = "errMesgLength"
PageMethods.GetLocalRessources(key, onSucess, onError);
return false;
}
}
else {
imei.style.border = "1px solid red";
key = "errMesgIMEI"
PageMethods.GetLocalRessources(key, onSucess, onError);
return false;
}
}
}
function onSucess(result) {
var lblMessage = document.querySelector(".lblMsgError");
lblMessage.innerHTML = result;
}
function onError(error) {
alert(error._message);
}
I cannot figure out why I keep getting this error:
Uncaught TypeError: Cannot read property 'options' of null
getFSREPlist
(anonymous function)
The error is referencing this line of code (21):
document.getElementById(elementidupdate).options.length=0;
What is weird is that it was working prior to this new google map api I just put on. Also, it is pulling the country code "1" and putting it in the drop down, but not the province code "19".
Here is the on page script:
getFSREPlist('1', 'fsrep-search-province', 'CountryID', '19');getFSREPlist('19', 'fsrep-search-city', 'ProvinceID', '3'); request.send(null);
Here is the full file:
function sack(file) {
this.xmlhttp = null;
this.resetData = function () {
this.method = "POST";
this.queryStringSeparator = "?";
this.argumentSeparator = "&";
this.URLString = "";
this.encodeURIString = true;
this.execute = false;
this.element = null;
this.elementObj = null;
this.requestFile = file;
this.vars = new Object();
this.responseStatus = new Array(2);
};
this.resetFunctions = function () {
this.onLoading = function () {};
this.onLoaded = function () {};
this.onInteractive = function () {};
this.onCompletion = function () {};
this.onError = function () {};
this.onFail = function () {};
};
this.reset = function () {
this.resetFunctions();
this.resetData();
};
this.createAJAX = function () {
try {
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
this.xmlhttp = null;
}
}
if (!this.xmlhttp) {
if (typeof XMLHttpRequest != "undefined") {
this.xmlhttp = new XMLHttpRequest();
} else {
this.failed = true;
}
}
};
this.setVar = function (name, value) {
this.vars[name] = Array(value, false);
};
this.encVar = function (name, value, returnvars) {
if (true == returnvars) {
return Array(encodeURIComponent(name), encodeURIComponent(value));
} else {
this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
}
}
this.processURLString = function (string, encode) {
encoded = encodeURIComponent(this.argumentSeparator);
regexp = new RegExp(this.argumentSeparator + "|" + encoded);
varArray = string.split(regexp);
for (i = 0; i < varArray.length; i++) {
urlVars = varArray[i].split("=");
if (true == encode) {
this.encVar(urlVars[0], urlVars[1]);
} else {
this.setVar(urlVars[0], urlVars[1]);
}
}
}
this.createURLString = function (urlstring) {
if (this.encodeURIString && this.URLString.length) {
this.processURLString(this.URLString, true);
}
if (urlstring) {
if (this.URLString.length) {
this.URLString += this.argumentSeparator + urlstring;
} else {
this.URLString = urlstring;
}
}
this.setVar("rndval", new Date().getTime());
urlstringtemp = new Array();
for (key in this.vars) {
if (false == this.vars[key][1] && true == this.encodeURIString) {
encoded = this.encVar(key, this.vars[key][0], true);
delete this.vars[key];
this.vars[encoded[0]] = Array(encoded[1], true);
key = encoded[0];
}
urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
}
if (urlstring) {
this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
} else {
this.URLString += urlstringtemp.join(this.argumentSeparator);
}
}
this.runResponse = function () {
eval(this.response);
}
this.runAJAX = function (urlstring) {
if (this.failed) {
this.onFail();
} else {
this.createURLString(urlstring);
if (this.element) {
this.elementObj = document.getElementById(this.element);
}
if (this.xmlhttp) {
var self = this;
if (this.method == "GET") {
totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
this.xmlhttp.open(this.method, totalurlstring, true);
} else {
this.xmlhttp.open(this.method, this.requestFile, true);
try {
this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
} catch (e) {}
}
this.xmlhttp.onreadystatechange = function () {
switch (self.xmlhttp.readyState) {
case 1:
self.onLoading();
break;
case 2:
self.onLoaded();
break;
case 3:
self.onInteractive();
break;
case 4:
self.response = self.xmlhttp.responseText;
self.responseXML = self.xmlhttp.responseXML;
self.responseStatus[0] = self.xmlhttp.status;
self.responseStatus[1] = self.xmlhttp.statusText;
if (self.execute) {
self.runResponse();
}
if (self.elementObj) {
elemNodeName = self.elementObj.nodeName;
elemNodeName.toLowerCase();
if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") {
self.elementObj.value = self.response;
} else {
self.elementObj.innerHTML = self.response;
}
}
if (self.responseStatus[0] == "200") {
self.onCompletion();
} else {
self.onError();
}
self.URLString = "";
break;
}
};
this.xmlhttp.send(this.URLString);
}
}
};
this.reset();
this.createAJAX();
}
var ajax = new Array();
function getFSREPlist(sel, elementidupdate, fsrepvariable, currentvalue) {
if (sel == '[object]' || sel == '[object HTMLSelectElement]') {
var FSREPID = sel.options[sel.selectedIndex].value;
} else {
var FSREPID = sel;
}
document.getElementById(elementidupdate).options.length = 0;
var index = ajax.length;
ajax[index] = new sack();
ajax[index].requestFile = 'http://www.cabcot.com/wp-content/plugins/firestorm-real-estate-plugin/search.php?' + fsrepvariable + '=' + FSREPID + '&cvalue=' + currentvalue;
ajax[index].onCompletion = function () {
ElementUpdate(index, elementidupdate)
};
ajax[index].runAJAX();
}
function ElementUpdate(index, elementidupdate) {
var obj = document.getElementById(elementidupdate);
eval(ajax[index].response);
}
You should call getFSREPlist when DOM is loaded. I ran
document.getElementById('fsrep-search-province').options.length=0
from chrome´s console. while page was still loading and caused that same error.
http://i.imgur.com/GBFizq1.png