GET http://ws-xxx/previewJsonP/?callback=jQuery15105377634419128299_1333636959724&htmlcontent=%3Cp%3EVolunteer+and+be+part+of+the+World%26rsquo%3Bs+Largest+Music+Festival!+To+apply+to+become+a+xxx+STAR+Volunteer+please+complete%2C+sign+and+return+the+2012+xxx+New+Volunteer+Application.+Applications+should+be+mailed+to%3A+xxx+STAR+Volunteer%2C+200+N.+Harbor+Drive%2C+Milwaukee%2C+WI+53202+or+faxed+to%3A+414-287-4495%3C%2Fp%3E%0A%3Cp%3E%3Cbr+%2F%3E%3Ca+href%3D%22http%3A%2F%2Fwww.xxx.com%2FContent%2Fpdf%2F2012-volunteer-app.pdf%22%3EDownload+the+2012+Volunteer+Application%3C%2Fa%3E%3C%2Fp%3E&_=1333636964810 500 (Internal Server Error)
d.ajaxTransport.sendjquery-1.5.1.min.js:19
d.extend.ajaxjquery-1.5.1.min.js:19
(anonymous function)112:27
Ejquery-1.5.1.min.js:19
d.event.handlejquery-1.5.1.min.js:19
d.event.add.k.handle.m
The code. I have this in the live site.
public class AllowCrossSiteJsonAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
base.OnActionExecuting(filterContext);
}
}
[AllowCrossSiteJson]
[ValidateInput(false)]
public ActionResult Preview(int? id, FormCollection collection, ContentPageEdit obj, string htmlContent)
{
obj.ContentBody = htmlContent;
return new JsonpResult
{
Data = new { content = obj.ContentBody },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
//return Json(obj, JsonRequestBehavior.AllowGet);
}
I have this code being executed in an admin section:
$('#preview').live('click', function (e) {
// Code...
var theContentBody = $('#ContentBody').val();
try{
$.getJSON("http://ws-devweb1.dmz.sf/preview/htmlContent=" + theContentBody, function (data) {
alert(data.content);
});
}
catch(e){alert(e);}
});
XMLHttpRequest cannot load http://xxx.com/preview/htmlContent=%3Cp%3EVolunteer%20and%20be%20part%20of%20the%20World’s%20Largest%20Music%20Festival!%20To%20apply%20to%20become%20a%xxx%20STAR%20Volunteer%20please%20complete,%20sign%20and%20return%20the%202012%xxx%20New%20Volunteer%20Application.%20Applications%20should%20be%20mailed%20to:%xxx%20STAR%20Volunteer,%20200%20N.%20Harbor%20Drive,%20Milwaukee,%20WI%2053202%20or%20faxed%20to:%20414-287-4495%3C/p%3E%3Cp%3E%3Cbr%20/%3E%3Ca%20href=%22http://www.xxx.com/Content/pdf/2012-volunteer-app.pdf%22%3EDownload%20the%202012%20Volunteer%20Application%3C/a%3E%3C/p%3E. Origin http://localhost:40304 is not allowed by Access-Control-Allow-Origin.
Xequence
Contributor
4313 Points
1528 Posts
Re: .getJSON cross domain request 500 error
Apr 05, 2012 02:18 PM|LINK
public class AllowCrossSiteJsonAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*"); base.OnActionExecuting(filterContext); } } [AllowCrossSiteJson] [ValidateInput(false)] public ActionResult Preview(int? id, FormCollection collection, ContentPageEdit obj, string htmlContent) { obj.ContentBody = htmlContent; return new JsonpResult { Data = new { content = obj.ContentBody }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; //return Json(obj, JsonRequestBehavior.AllowGet); }$('#preview').live('click', function (e) { // Code... var theContentBody = $('#ContentBody').val(); try{ $.getJSON("http://ws-devweb1.dmz.sf/preview/htmlContent=" + theContentBody, function (data) { alert(data.content); }); } catch(e){alert(e);} });I am following this link: http://stackoverflow.com/questions/7547672/ajax-json-post-to-controller-across-domains-not-allowed-by-access-control-all
Credentials