2017-08-20 158 views
0

我想用控制器和ajax同時使用'Blog Entry'和'Blog Entry Photo'。另一方面,如果只採用「BlogEntry」,則在採取這兩種方法時(BlogEntry和BlogEntryPhoto)沒有任何問題,因此存在問題:「此請求已被阻止,因爲敏感信息可能會泄露給第三方網站當它用於GET請求時,爲了允許GET請求,將JsonRequestBehavior設置爲AllowGet。「此請求已被阻止,因爲在GET請求中使用此信息時,敏感信息可能會泄露給第三方網站。

我認爲問題出現在「Blog Entry Photo」中,因爲它有photopath列,如「/Content/img/blog/25052017_2334_400x400.jpg」。 我用JsonResult但它不工作

return Json(new { Success = true, BlogEntries = blogEntries, BlogEntryPhotos = blogEntryPhotos}, JsonRequestBehavior.AllowGet); 

我應該怎麼辦?

+0

在VS,感謝我的斷點檢查數據是否採取的是客戶端,但數據取。我認爲這個問題是AJAX上的MIMETYPE的PhotoPath問題。 – pinyil

回答

0

最後,我最終解決了PhotoPath數據產生的這個問題。首先,在控制器處,BlogEntry和BlogEntryPhotos的數據被一起掃描,然後在視圖中將該數據解析爲對象。

控制器

List<BlogEntry> blogEntries = _blogEntryRepo.GetAll(x => x.IsActive.Value && x.PlaceMarkerID == placeMarker.Id, null, "BlogEntryPhotoes").ToList(); 
JsonSerializerSettings jss = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; 
return Json(new { Success = true, BlogEntries = JsonConvert.SerializeObject(blogEntries, Formatting.Indented, jss) }, JsonRequestBehavior.AllowGet); 

VIEW

$.ajax({ 
     url: "/Map/GetBlogEntries", 
     type: "post", 
     datatype: "json", 
     data: placeMarker, 
     success: function (response) { 
     if (response.Success) { 
      var BlogEntries = JSON.parse(response.BlogEntries); 
      //BlogEntries[i].Title can be used 
      //BlogEntries[i].BlogEntryPhotoes[0].PhotoPath can be used 
     } 
     else { 
       //do something 
    } 
     }, 
     error: function (xhr, status) { 
     //do something 
     } 
});