I am passing a basic function into a view on a different machine. I want to return a view from different url and pass in my data somehow and get a returned view with the strongly typed model inside.
I am partially through the issue, but it comes down to getting an actionresult to render a different actionresult.
something like, www.mypublicapp.com/abc/def would be the actionresult that I would pass my data using a $.toJSON. I get a 500 error on get command. How can I fix this?
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.
you are trying to use native cors with json. you must use a browser that supports this. if you use firefox, see the jquery ajax notes for a fix. chrome and safari shoudl work fine. you will need IE 10 or greater to use IE.
Xequence
Contributor
4313 Points
1528 Posts
.getJSON cross domain request 500 error
Apr 04, 2012 09:26 PM|LINK
I am passing a basic function into a view on a different machine. I want to return a view from different url and pass in my data somehow and get a returned view with the strongly typed model inside.
I am partially through the issue, but it comes down to getting an actionresult to render a different actionresult.
something like, www.mypublicapp.com/abc/def would be the actionresult that I would pass my data using a $.toJSON. I get a 500 error on get command. How can I fix this?
Credentials
BrockAllen
All-Star
27516 Points
4897 Posts
MVP
Re: .getJSON cross domain request 500 error
Apr 04, 2012 09:51 PM|LINK
What's the server error?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
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
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: .getJSON cross domain request 500 error
Apr 06, 2012 03:20 AM|LINK
you are trying to use native cors with json. you must use a browser that supports this. if you use firefox, see the jquery ajax notes for a fix. chrome and safari shoudl work fine. you will need IE 10 or greater to use IE.
Xequence
Contributor
4313 Points
1528 Posts
Re: .getJSON cross domain request 500 error
Apr 06, 2012 03:12 PM|LINK
This looks promising! http://www.west-wind.com/weblog/posts/2012/Apr/02/Creating-a-JSONP-Formatter-for-ASPNET-Web-API
Credentials
asteranup
All-Star
30184 Points
4906 Posts
Re: .getJSON cross domain request 500 error
Apr 07, 2012 07:26 AM|LINK
Hi,
You may check this-
http://forums.asp.net/p/1782901/4899363.aspx/1?Re+problem+in+return+result+Ajax
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog