“Request blocked because of sensitive information” error using jQuery / JSON

I had a very simple jQuery method to call a Web API method, such as this:

function GetLogs() {
request = $.ajax({
url: “Home/Get”,
type: “GET”,
dataType: ‘json’,
async: false,
contentType: “application/json;charset=utf-8”,
success: function (request, status, error) {
alert(‘success’);
},
error: function (request, status, error) {
alert(‘error’);
}
});
}

Behind the scenes, I had this little test method that returned a couple of string values:

public ActionResult Get() {
List<string> results = new List<string>();
results.Add(“one”);
results.Add(“two”);
return Json(results);
}

When I returned the data from this innocuous piece of code, I got this unfortunate error:

 “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.”

It was a simple fix – I just had to add the AllowGet method to my “Json” method call:

public ActionResult Get() {
List<string> results = new List<string>();
results.Add(“one”);
results.Add(“two”);
return Json(results, JsonRequestBehavior.AllowGet);
}

And back came the data.

Advertisements

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: