From eff349fe6116603ed66a7a0dc946b970a144c353 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Mon, 10 Sep 2018 01:19:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A$.?= =?UTF-8?q?bc=E5=A2=9E=E5=8A=A0=E8=B7=A8=E5=9F=9F=E5=B8=A6Cookie=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=95=B0=E6=8D=AEcors:=20true?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/wwwroot/js/longbow.common.js | 9 ++++++++- Bootstrap.Admin/wwwroot/js/settings.js | 11 +++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/js/longbow.common.js b/Bootstrap.Admin/wwwroot/js/longbow.common.js index 89b8c1ff..95c75c7d 100644 --- a/Bootstrap.Admin/wwwroot/js/longbow.common.js +++ b/Bootstrap.Admin/wwwroot/js/longbow.common.js @@ -123,6 +123,7 @@ loadingTimeout: 10000, callback: false, $element: false, + cors: false, contentType: 'application/json', dataType: 'json', method: 'get' @@ -143,19 +144,25 @@ if (options.url) { var data = options.method === 'get' ? options.data : JSON.stringify(options.data); - $.ajax({ + var ajaxSettings = { url: $.formatUrl(options.url) + options.id, data: data, method: options.method, contentType: options.contentType, dataType: options.dataType, + crossDomain: false, success: function (result) { success(result); }, error: function (XMLHttpRequest, textStatus, errorThrown) { success(false); } + }; + if (options.cors) $.extend(ajaxSettings, { + xhrFields: { withCredentials: true }, + crossDomain: true }); + $.ajax(ajaxSettings); } function success(result) { if ($.isFunction(options.callback)) { diff --git a/Bootstrap.Admin/wwwroot/js/settings.js b/Bootstrap.Admin/wwwroot/js/settings.js index 759d5a88..c679d61b 100644 --- a/Bootstrap.Admin/wwwroot/js/settings.js +++ b/Bootstrap.Admin/wwwroot/js/settings.js @@ -57,14 +57,14 @@ else options.url = item.Url; $.bc({ url: options.url, - method: "post", + cors: !item.Self, callback: function (result) { if ($.isArray(result)) { - var html = '
{2}{0}
{3}
{7}
'; + var html = '
{2}{0}
{3}
{6}
'; var content = result.sort(function (x, y) { return x.Key > y.Key ? 1 : -1; }).map(function (ele) { - return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value, '', $.format(item.Url, ele.Key), item.Self, Math.max(0, ele.Interval - Math.round((new Date() - new Date(ele.CreateTime.replace(/-/g, '/'))) / 1000))); + return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value, $.format(item.Url, ele.Key), item.Self, Math.max(0, ele.Interval - Math.round((new Date() - new Date(ele.CreateTime.replace(/-/g, '/'))) / 1000))); }).join(''); $sortable.append($.format('
{0}
', item.Desc)); $sortable.append(content); @@ -80,7 +80,6 @@ }); }; - var listCache = function (options) { $.bc({ url: options.url, method: "post" }); }; $('a[data-method]').on('click', function (e) { e.preventDefault(); e.stopPropagation(); @@ -96,8 +95,8 @@ listCacheUrl(options); }).last().trigger('click'); $sortable.on('click', '.btn', function () { - $(this).tooltip('dispose'); - listCache({ url: $(this).attr('data-url') }); + var $this =$(this).tooltip('dispose'); + $.bc({ url: $this.attr('data-url'), cors: $this.attr('data-self') === 'false' }); listCacheUrl(); });