0

次のJavascriptを作成しましたが、「無効なJSONプリミティブ:strSeason」というエラーが発生します。残りの構文は問題ないようですが、「data」パラメーターを正しく取得できないようです。誰かが構文を手伝ってくれますか?

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 に答える