I am using the Javascript Client Object model to access some information from a list. Below is the code I am using:
function getDeptInfo(id) {
//var value = SP.ListOperation.Selection.selectListItem(id, bSelect);
var ctx = new SP.ClientContext.get_current();
this.website = ctx.get_web();
this.listCollection = website.get_lists();
this.oDeptList = listCollection.getByTitle('NavStructure');
this.oDeptItem = oDeptList.getItemById(id);
ctx.load(oDeptItem, 'Department_x003a_photoname', 'Department_x003a_phonenbr', 'Department_x003a_faxnumber', 'Department_x003a_email', 'Department_x003a_hours', 'Department_x003a_siteurl', 'Department_x003a_pictureurl', 'Department', 'ID');
ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
if (oDeptItem.get_item('Department') != null) {
$('#department').html(oDeptItem.get_item('Department').get_lookupValue());
$('#contact').html(oDeptItem.get_item('Department_x003a_photoname').get_lookupValue());
//hours not in profile list? Hardcoding for now...
//$('#hours').html(oDeptItem.get_item('Department_x003a_Main_x0020_Cont').get_lookupValue());
$('#hours').html(oDeptItem.get_item('Department_x003a_hours').get_lookupValue());
$('#phone').html(oDeptItem.get_item('Department_x003a_phonenbr').get_lookupValue());
$('#fax').html(oDeptItem.get_item('Department_x003a_faxnumber').get_lookupValue());
$('#email').html(oDeptItem.get_item('Department_x003a_email').get_lookupValue());
$('#DeptLink').attr('href', oDeptItem.get_item('Department_x003a_siteurl').get_lookupValue());
$('#deptHead').attr('src', oDeptItem.get_item('Department_x003a_pictureurl').get_lookupValue());
}
}
For some reason when I run this in Firefox as an anonymous user it works fine. When I run it from IE as an anonymous user it errors out with:
Error:The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Does anyone know why this would happen? Any suggestions on how to resolve the error?
UPDATE:
I just tested this on a machine that is outside of our domain and everything works fine. it only happens when internal machines run the code. I have also since tested it with Safari and Chrome and neither of those throw errors - only IE.
Also, if I set "Web Page security validation" under General Settings to "Off" IE 8 stops throwing the error. Any idea what could cause this?