Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX调用无法与控制器操作一起使用_Javascript_Jquery_Ajax_Asp.net Mvc_Sharepoint - Fatal编程技术网

Javascript AJAX调用无法与控制器操作一起使用

Javascript AJAX调用无法与控制器操作一起使用,javascript,jquery,ajax,asp.net-mvc,sharepoint,Javascript,Jquery,Ajax,Asp.net Mvc,Sharepoint,萨拉蒙·阿勒库姆 我的AJAX调用没有调用ASP.NET MVC Web应用程序项目中的控制器操作 下面是我在Javascript中的AJAX调用,接下来是控制器的操作 AJAX调用 var requestUrl = '/Home/GetCurrentUser'; $.ajax({ url: requestUrl, type: 'GET', dataType: 'json', contentType: 'applic

萨拉蒙·阿勒库姆

我的AJAX调用没有调用ASP.NET MVC Web应用程序项目中的控制器操作

下面是我在Javascript中的AJAX调用,接下来是控制器的操作

AJAX调用

    var requestUrl = '/Home/GetCurrentUser';
    $.ajax({
        url: requestUrl,
        type: 'GET',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function(data)
        {
            debugger;
            alert(data);
        },
        error: function (xhr, status, error)
        {
            debugger;
            alert(error);
        }
控制器动作

[SharePointContextFilter]
        public JsonResult GetCurrentUser()
        {
            CurrentUserModel um = new CurrentUserModel();
            try
            {
                Microsoft.SharePoint.Client.User spUser = null;
                var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
                using (var clientContext = spContext.CreateUserClientContextForSPHost())
                {
                    if (clientContext != null)
                    {
                        spUser = clientContext.Web.CurrentUser;

                        clientContext.Load(spUser, user => user.Title, user => user.Email, user => user.LoginName);

                        clientContext.ExecuteQuery();

                        um.Name = spUser.Title;
                        um.Email = spUser.Email;
                        um.LoginName = spUser.LoginName;
                    }
                }

                SharePointBoxOnline.Common.User u = UserManager.Instance.GetUserByEmail(um.Email);

                if (u != null)
                {
                    um.ClientId = u.FK_Client_ID;
                    um.UserId = u.User_ID;
                }
            }
            catch (Exception e)
            {
                SharePointBoxOnlineAppWeb.Classes.LogsManager.LogException(e.Message, e.StackTrace, System.Web.HttpContext.Current.Request.Url.ToString(), "Added logging functionality to store the exception information in the Database", DateTime.Now);
            }

            return Json(um, JsonRequestBehavior.AllowGet);
        }
AJAX中的错误结果是

错误.说明

无效字符

地位

解析器错误

xhr.responseText

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Error</title>
    <link href="/Content/css?v=MDbdFKJHBa_ctS5x4He1bMV0_RjRq8jpcIAvPpKiN6U1" rel="stylesheet"/>

</head>
<body>
    <div class="container">
        <div class="jumbotron">
            <h2>An unexpected error has occurred.</h2>
            <p>Please try again by launching the app installed on your site.</p>
        </div>
    </div>

<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
    {"appName":"Internet Explorer","requestId":"673b269bf2c74e39a9496d69f3e0b62e"}
</script>
<script type="text/javascript" src="http://localhost:14069/4b2e31c8e2cf413facce9558ed0cb3ff/browserLink" async="async"></script>
<!-- End Browser Link -->

</body>
</html>

错误
发生意外错误。
请通过启动您网站上安装的应用程序重试

{“appName”:“Internet Explorer”,“requestId”:“673b269bf2c74e39a9496d69f3e0b62e”}
谢谢Stackoverflow和Stackoverflow的成员,如果您需要更多详细信息,请告诉我


谢谢

什么不起作用?你正在使用控制器方法。浏览器控制台中显示了哪些错误?您从后端发送了什么字符编码?Salaam@William感谢您的帮助我猜您是在询问“application/json”我想接收json作为数据谢谢您在Ajax请求中设置了内容类型,但这指的是您在请求中发送的正文。accept头告诉服务器应该发送回哪些内容。但我更想知道是否有一些奇怪的聊天编码,比如UTF-16谢谢你澄清[微笑]@William不,我没有这样的编码我很抱歉误会了谢谢
$.ajax({
    url: requestUrl,
    type: 'GET',
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    success: function(data)
    {
        debugger;
        alert(data);
    },
    error: function (xhr, status, error)
    {
        debugger;
        alert(error);
    }
});