I use a free api in order to gather informationfrom the users Ip-adress.
This is the method:
public JsonResult GetIp()
{
string url = "http://ip-api.com/json";
dynamic googleResults = new Uri(url).GetDynamicJsonObject();
return Json(googleResults, JsonRequestBehavior.AllowGet);
}
The method is supposed to get called when the page is rendered so I am thinking something like this:
$(document).ready(function () {
$.ajax({
type: "POST",
url: '@Url.Action("GetIp", "Home")',
contentType: "application/json; charset=utf-8",
dataType: "json",
//Here i need code that receives the Json from the controller...
});
});
Also, is this the best way to go about a task like this? I've been reading that Json could also be passed as a simple string? Any tips on best practice appreciated. Thanks.