0
當我加入控制器動作類我返回JSON對象:動態添加鏈接動作產生「此請求已被封鎖...」錯誤
return Json(new { categoryName = category.Name, isPrimary = isPrim ? "1" : "-1", categoryId = categoryId }, JsonRequestBehavior.AllowGet);
在JS處理函數我頁面上添加項目:
...
var totalLink = "<li style='color: #bbbbbb;'>" + result.categoryName + "<a class='removeCategoryButton' href='#lnk#'>remove</a></li>";
var lnk = '@Url.Action("RemoveCategoryFromLocation", "Location", new{locationId = Model.Location.TicketId, categoryId=-1})';
totalLink = totalLink.replace('#lnk#', lnk);
totalLink = totalLink.replace('-1', result.categoryId);
$('#otherCategories').append(totalLink);
...
當我點擊刪除鏈接我調用下面的函數:
$(function() {
$('.removeCategoryButton').click(function (event) {
event.preventDefault();
$.ajax({
url: this.href,
type: 'POST',
context: this,
success: function (result) {
if(result.categoryName == 1) {
$(this).closest('li').remove();
}
}
});
return false;
});
});
但我得到以下錯誤:
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
只有當我添加項目並希望在添加頁面後立即刪除它時,纔會發生此錯誤。如果我刷新頁面並單擊刪除鏈接,它的工作原理沒有問題。
只是要注意,當我從上面的類別中得到的錯誤被刪除,所以調用它只是從某種原因彈出此錯誤。
它的工作原理。謝謝 :) – 1110