相关疑难解决方法(0)

如何通过JavaScript发送跨域POST请求?

如何通过JavaScript发送跨域POST请求?

注意 - 它不应该刷新页面,然后我需要抓取并解析响应.

javascript ajax cross-domain

553
推荐指数
9
解决办法
50万
查看次数

ASP.net MVC返回JSONP

我希望跨域返回一些JSON,我知道这样做的方法是通过JSONP而不是纯JSON.我正在使用ASP.net MVC所以我正在考虑只是扩展JSONResult类型然后extendig Controller,以便它还实现了一个Jsonp方法.这是最好的解决方法,还是内置的ActionResult可能会更好?

编辑:我继续前进并做到了.仅供参考,我添加了一个新结果:

public class JsonpResult : System.Web.Mvc.JsonResult
    {
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpResponseBase response = context.HttpContext.Response;

            if (!String.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            else
            {
                response.ContentType = "application/javascript";
            }
            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }
            if (Data != null)
            {
                // The JavaScriptSerializer type was marked as obsolete prior to .NET Framework 3.5 SP1
#pragma warning disable 0618
                HttpRequestBase request = context.HttpContext.Request;

                JavaScriptSerializer serializer …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc json jsonp

72
推荐指数
3
解决办法
4万
查看次数

标签 统计

ajax ×1

asp.net-mvc ×1

cross-domain ×1

javascript ×1

json ×1

jsonp ×1