This request has been blocked because sensitive information is leaked to a third-party website when used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet ., Jsonrequestbehavior

Source: Internet
Author: User

This request has been blocked because sensitive information is leaked to a third-party website when used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet ., Jsonrequestbehavior
1. Problem Description

Mvc obtains all image information from a path. The ajax method is as follows:

function getimages(day) {            var year = $("#selYear").val();            var month = $("#selMonth").val();            selday = day;            var date = year + "." + month + "." + (day < 10 ? "0" + day : day);            $("#selInfo").text(date);            $("#fileContainer").html("");            $.ajax({                url: '@Url.Content("/MedOffice/Photo/ImageList")' + '?path=' + date,                type: 'GET',                dataType: 'text/json',                success: function(data) {                    alert(data);                },                error: function(xmlHttpRequest, textStatus, errorThrown) {                    console.log(xmlHttpRequest);                    alert(xmlHttpRequest);                }            });        }

The following results are returned for invocation:

2. Problem Analysis

Change json to jsonresult and set it:

JsonRequestBehavior = JsonRequestBehavior. AllowGet // Add this sentence

3. Correct Request Method
public JsonResult ImageList(string path)        {            List<FileInfoViewModel> files = new List<FileInfoViewModel>();            try            {                var datetime = DateTime.Parse(path);                var mypath = path.Replace(datetime.Year + ".", "");                var destpath = "~/AllDocuments/" + datetime.Year + "/" + mypath;                destpath = Server.MapPath(destpath);                if (Directory.Exists(destpath))                {                    foreach (string filepath in Directory.GetFiles(destpath))                    {                        FileInfoViewModel model = new FileInfoViewModel                        {                            Path = filepath,                            Name = Path.GetFileNameWithoutExtension(filepath)                        };                        try                        {                            var fileInfo = new FileInfo(filepath);                            model.Size = fileInfo.Length.ToString();                            model.Date = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss");                        }                        catch (Exception e)                        {                            LogHelper.Error(e);                        }                    }                }                return new JsonResult()                {                    Data = new                    {                        result = 0,                        messate = "",                        data = files                    },                    JsonRequestBehavior = JsonRequestBehavior.AllowGet                };            }            catch (Exception e)            {                LogHelper.Error(e);                return new JsonResult()                {                    Data = new                    {                        result = -99,                        messate = e.Message,                        data = files                    },                    JsonRequestBehavior = JsonRequestBehavior.AllowGet                };            }        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.