0

我编写了以下 Javascript,但收到错误“无效的 JSON 原语:strSeason”。语法的其余部分似乎很好,但我似乎无法正确获取“数据”参数。任何人都可以帮我语法吗?

TagBuilder script = new TagBuilder("script");
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("language", "javascript");
            // ReSharper disable LocalizableElement
            script.InnerHtml = @"

            $.ajax({
                type: 'POST',
                async: true,
                contentType: 'application/json; charset=utf-8',
                dataType: 'html',
                url: '/en-US/" + areaName + '/' + controllerName + '/' + actionName + @"',
                data: " + "{strSeason:'" + season + "', strTeam:'" + team + @"'},
                beforeSend: function(xhr){
                $(this).addClass('ajaxRefreshing');
                xhr.setRequestHeader('X-Client', 'jQuery');
                },
                success: function(html){
                $(this).html(html);
                },
                complete: function(){
                $(this).removeClass('ajaxRefreshing');
                }
            });

        ";
4

1 回答 1

0

将名称括在引号中

data: " + "{'strSeason':'" + season + "', 'strTeam':'" + team + @"'},

编辑:您可能只需要发送 JSON 字符串,因此将整个字符串括在引号中。

data: " + "\"{'strSeason':'" + season + "', 'strTeam':'" + team + "'}\"" +@",
于 2012-07-24T08:37:26.483 回答