Posts Tagged ‘json’

This was the first q/a that popped up for me when trying to solve the same problem using .net MVC as the source of my data. I realize this doesn’t solve the php question but it is related enough to be valuable.

I am using .net mvc. The blog post from Greg Brant worked for me. Ultimately you create an attribute :

[HttpHeaderAttribute("Access-Control-Allow-Origin", "*")]

That you are able to add to controller actions.

eg:

public class HttpHeaderAttribute : ActionFilterAttribute
{
   public string Name { get; set; }
   public string Value { get; set; }
   public HttpHeaderAttribute(string name, string value)
   {
      Name = name;
      Value = value;
   }

   public override void OnResultExecuted(ResultExecutedContext filterContext)
   {
      filterContext.HttpContext.Response.AppendHeader(Name, Value);
      base.OnResultExecuted(filterContext);
   }
}

and then using it with:

[HttpHeaderAttribute("Access-Control-Allow-Origin", "*")]
public ActionResult MyVeryAvailableAction(string id)
{
    return Json( "Some public result" );
}

Source: http://goo.gl/WBsnr

Other view of the problem in…

Advertisements