目前仅支持IE7/8不支持IE11和谷歌

对于跨域情况,目前找到如果jquery是get获取方式,可以配置web.config相关属性,具体powershell命令如下:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

$localFarm = Get-SPFarm

$webapp = Get-SPWebApplication "http://wtcsps98"

# Remove old web.config modifications of MyAuthenticationProvider
$oldMods = @();
$webapp.WebConfigModifications | ? { $_.Owner -eq "CrossSiteScripting" } | % {
$oldMods = $oldMods + $_
} $oldMods | % {
$webapp.WebConfigModifications.Remove($_)
} # update the Web Application and apply all existing web.config modifications - this executes the "remove" actions from above
$webapp.Update()
[Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplyWebConfigModifications() #Wait until web.config modifications finished by timer job
while( (Get-SPTimerJob | ? { $_.Name -eq "job-webconfig-modification"}) -ne $null ) {
Write-Host "." -NoNewline
Start-Sleep 1
} # New web.config modifications for MyAuthenticationProvider
$myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Allow-Origin'][@value='http://wtcsps99']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
#0 = for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Allow-Origin' value='http://wtcsps99' />"
$webapp.WebConfigModifications.Add($myModification1) $myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Request-Method'][@value='GET,POST,HEAD,OPTIONS']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Request-Method' value='GET,POST,HEAD,OPTIONS' />"
$webapp.WebConfigModifications.Add($myModification1) $myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Request-Headers'][@value='Content-Type,Authorization']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Request-Headers' value='Content-Type,Authorization' />"
$webapp.WebConfigModifications.Add($myModification1) $myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Allow-Credentials'][@value='true']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Allow-Credentials' value='true' />"
$webapp.WebConfigModifications.Add($myModification1) $webapp.Update()
[Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplyWebConfigModifications() #Wait until web.config modifications finished by timer job
while( (Get-SPTimerJob | ? { $_.Name -eq "job-webconfig-modification"}) -ne $null ) {
Write-Host "." -NoNewline
Start-Sleep 1
}

  

另外也需要在javascript里面进行相关配置,具体如下:

var Module = window.Module || {};
Module.GetTasks = (function () {
var pub = {},
_userId, //userID of current user
_tasks = [], //List of our tasks
_options = {
listName: "Tasks List", //Name of list we want
container: "#TaskListContainer",
pulicUrl: "http://wtcsps98/sites/bpmmgmt"//id of html element we're rendering our list of tasks in
};
pub.init = function () {
var clientContext = new SP.ClientContext.get_current();
_userId = clientContext.get_web().get_currentUser();
clientContext.load(_userId); //clientContext.load(_userId);
clientContext.executeQueryAsync(GetDocDetail, _onQueryFailed); }; function ReturnTaskCount(results) {
var _tasks = results.d.results;
var count = 0;
var year = '2016';
$.each(_tasks, function (index, task) {
console.log(task.Status);
year = GetYearValue(task.Title);
if (parseInt(year) > 2014 && task.Status == 'Not Started') {
count++;
} });
return count;
}
function getCountFormDigest(webUrl, listName) {
var count = 0;
$.support.cors = true;
$.ajax({
url: webUrl + "/_api/contextinfo",
method: "POST",
headers: { "Accept": "application/json; odata=verbose" },
async: false,
xhrFields: { "withCredentials": true },
crossDomain: true,
success: function (data) {
count = getCountBySpecifiedList(data, listName, webUrl);
},
error: function (error) {
console.log("Error in getting List: " + error);
//$(_options.container).html("Error retrieving your " + listName + ".");
}
});
return count;
}
function GetYearValue(taskTitle) {
var year = '2016';
var sTitle = taskTitle;
var aTitle = sTitle.split('-');
var title = aTitle[2].replace(/^\s*/, '');
year = title.substring(3, 7);
console.log(year);
return year;
}
function getCountBySpecifiedList(data, listName, webUrl) {
var url = '', caml = '';
var count = 0;
var viewXml = "<View><Query><Where><Or><Eq><FieldRef Name='AssignedTo' /><Value Type='Integer'><UserID/></Value></Eq><Membership Type='CurrentUserGroups'><FieldRef Name='AssignedTo' /> </Membership></Or></Where></Query></View>";
//var viewXml = "<View><Query><Where><And><And><Or><Eq><FieldRefName='AssignedTo'/><ValueType='Integer'><UserID/></Value></Eq><MembershipType='CurrentUserGroups'><FieldRefName='AssignedTo'/></Membership></Or><Neq><FieldRefName='Status'/><ValueType='Choice'>Completed</Value></Neq></And><Gt><FieldRefName='Created'/><ValueType='DateTime'>2014-09-28T12:00:00Z</Value></Gt></And></Where></Query></View>"
$.support.cors = true;
$.ajax({
url: webUrl + "/_api/web/lists/getbytitle('" + listName + "')/getitems",
method: "POST",
async: true,
//xhrFields: { "withCredentials": true },
crossDomain: true,
beforeSend: function(request) {
request.setRequestHeader('Access-Control-Allow-Origin', 'http://wtcsps99');
request.withCredentials = true;
},
data: "{ 'query' : {'__metadata': { 'type': 'SP.CamlQuery' }, \"ViewXml\": \""
+ viewXml + "\" }}",
headers: {
"X-RequestDigest": data.d.GetContextWebInformation.FormDigestValue,
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: function (results) {
count = ReturnTaskCount(results);
},
error: function (error) {
console.log("Error in getting List: " + listName);
//$(_options.container).html("Error retrieving your " + listName + ".");
}
});
return count;
}
function GetDocDetail() {
console.log(_userId.get_loginName());
var loginName = _userId.get_loginName();
if (loginName == 'i:0#.w|wtc\\setup.moss') {
$(_options.container).html('its over');
//return; }
var showHtml = '';
showHtml = '<div class="navitems_mc">';
showHtml += '<ul class="activeTit">';
$.support.cors = true;
$.ajax({
url: _options.pulicUrl + "/_api/web/lists/GetByTitle('Application Information')/items",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
async: false,
xhrFields: { withCredentials: true },
crossDomain: true,
beforeSend: Loading,
success: function (data) {
var appInfo = data.d.results;
if (appInfo) {
var count = 0;
var taskUrl = '';
var countTask = 0;
$.each(appInfo, function (index, item) {
taskUrl = item.SiteUrl + '/Lists/Tasks/MyItems.aspx';
countTask = getCountFormDigest(item.SiteUrl, item.TaskListName);
if (countTask > 0) {
showHtml += '<li class="navitems_mc_ul">';
showHtml += '<div class="classifydivv2" ><h2>' + item.CName + '</h2>';
showHtml += '<a href="' + taskUrl + '"><em>' + countTask + '</em></a>';
showHtml += '</div>';
showHtml += '</li>';
} });
}
},
error: function (xhr) {
console.log(xhr.status + ': ' + xhr.statusText);
}
});
showHtml += '</ul></div>';
$(_options.container).html(showHtml);
}
function Loading() {
var showHtml = '<b>数据加载中,请稍后...</b>';
$(_options.container).html(showHtml);
}
function _onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
} return pub; }());

  

解决SHAREJPOINT 跨域问题的更多相关文章

  1. 解决cookie跨域访问

    一.前言 随着项目模块越来越多,很多模块现在都是独立部署.模块之间的交流有时可能会通过cookie来完成.比如说门户和应用,分别部署在不同的机器或者web容器中,假如用户登陆之后会在浏览器客户端写入c ...

  2. 如何解决ajax跨域问题(转)

    由 于此前很少写前端的代码(哈哈,不合格的程序员啊),最近项目中用到json作为系统间交互的手段,自然就伴随着众多ajax请求,随之而来的就是要解决 ajax的跨域问题.本篇将讲述一个小白从遇到跨域不 ...

  3. 用nginx的反向代理机制解决前端跨域问题

    什么是跨域以及产生原因 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,或是a页面为ip地址,b页面为域名地址,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制 ...

  4. 用iframe设置代理解决ajax跨域请求问题

    面对ajax跨域请求的问题,想用代理的方式来解决这个跨域问题.在服务器端创建一个静态的代理页面,在客户端用iframe调用这个代理 今天在项目中需要做远程数据加载并渲染页面,直到开发阶段才意识到aja ...

  5. CP="CAO PSA OUR" 用P3P header解决iframe跨域访问cookie

    1.IE浏览器iframe跨域丢失Session问题 在开发中,我们经常会遇到使用Frame来工作,而且有时是为了跟其他网站集成,应用到多域的情况下,而Iframe是不能保存Session的因此,网上 ...

  6. 看小白如何解决ajax跨域问题

    由于此前很少写前端的代码(哈哈,不合格的程序员啊),最近项目中用到json作为系统间交互的手段,自然就伴随着众多ajax请求,随之而来的就是要解决ajax的跨域问题.本篇将讲述一个小白从遇到跨域不知道 ...

  7. 如何解决ajax跨域问题

    如何解决ajax跨域问题(转) 由 于此前很少写前端的代码(哈哈,不合格的程序员啊),最近项目中用到json作为系统间交互的手段,自然就伴随着众多ajax请求,随之而来的就是要解决 ajax的跨域问题 ...

  8. 解决js跨域问题

    如何解决js跨域问题 Js跨域问题是web开发人员最常碰到的一个问题之一.所谓js跨域问题,是指在一个域下的页面中通过js访问另一个不同域下 的数据对象,出于安全性考 虑,几乎所有浏览器都不允许这种跨 ...

  9. 说说JSON和JSONP,浅析JSONP解决AJAX跨域问题

    说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决?这两个问题目前都有不同的解决方案,比如数据可以用自定义字符串或者用XML来描述,跨域可以通过服 ...

随机推荐

  1. 查询数据库中的表格---通过构造方法将数据存入到List集合中---遍历进行输出

    package cn.jy.demo; import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.Res ...

  2. How to Create Triggers in MySQL

    https://www.sitepoint.com/how-to-create-mysql-triggers/ I created two tables: CREATE TABLE `sw_user` ...

  3. gcc -ldl 选项作用

    如果你的程序中使用dlopen.dlsym.dlclose.dlerror 显示加载动态库,需要设置链接选项 -ldl 加载动态链接库,首先为共享库分配物理内存,然后在进程对应的页表项中建立虚拟页和物 ...

  4. kbmmw 中简单返回 extjs 数据JSON

    以前,我们通过自己写json 来返回数据表的内容.在delphi 10.2.2中,官方自带了一个FDBatchMoveJSONWriter1 来直接处理数据库内容.把结果推送到浏览器客户端. 今天我们 ...

  5. Java日期时间使用总结[转载]

    Java日期时间使用总结   一.Java中的日期概述   日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式 ...

  6. vue中moudles的作用及使用方法

    1.作用:vuex允许把store分割为模块,每一个模块都有自己的state,actions,getters,mutations甚至是嵌套一些子模块,从上到下进行同样方式的分割 在文件src中创建一个 ...

  7. 第06章:MongoDB-CRUD操作--集合

    ①显示现有的集合 命令:show collections 或者show tables; ②创建集合 隐示 在MongoDB中,你不需要创建集合.当你插入一些文档时,MongoDB 会自动创建集合. d ...

  8. MyBatis(一)helloWorld程序

    一.准备两个jar包,第一个:下载myBatis-3.3.1.jar,这里是在CSDN网站处下载的,因为官网打不开.第二个:mysql-connector-java-5.0.8-bin.jar,这个j ...

  9. STM32F10X-定时器/计数器

    1.STM32F10X的计数器与定时器关系 当时钟连接外脉冲时是计数器:当时钟采用系统内部时钟时是定时器! 2.STM32F10X定时器的时钟源 STM32F10X定时器的时钟不是直接来至于APB1和 ...

  10. day32(表单校验js和jquery表单校验)

    校验用户名.密码.密码一直性. <style> .error { color: red } .success { color: green } </style> <scr ...