2011-06-21 23 views
0

私の以前のquestionに加えて、私はMVC3プロジェクトで同じ作業コード(MVC2用)を使用しようとしました。私は、jQuery.getJSONメソッドを使用することができないことを理解しました。ですから、代わりに$ .postと$ .ajaxメソッドを使用しようとしましたが、もう一度問題に直面しました。asp.net mvc 3 highchart

私はエラーを取得両方の方法で

「のJscriptを:JBが空かないオブジェクト」私を助けるために、事前に

$.post("Home/GetLineData", null, function (items) {     
      var series = []; 
      jQuery.each(items, function (itemNo, item) { 
       //Get the items from the JSON and add then     
       //to the data array of the series 
       series.push({ 
        name: item.Key, 
        data: item.Value 
       }) 
      }); 
      options.series = series; 
      chart = new Highcharts.Chart(options); 
      chart.render(); 
     }); 

$.ajax({ 
      type: "POST", 
      dataType: "json", 
      data: "{}", 
      contentType: "application/json; charset=utf-8", 
      url: "/Home/GetLineData", 
      cache: false, 
      succes: function (data) { 
       var series = []; 
       jQuery.each(data, function (itemNo, item) { 
        //Get the items from the JSON and add then     
        //to the data array of the series 
        series.push({ 
         name: item.Key, 
         data: item.Value 
        }) 
       }); 
       options.series = series; 
       //Create the chart 
       chart = new Highcharts.Chart(options); 
       chart.render(); 
      }, 
      error: function (XMLHttpRequest, textStatus, errorThrown) { 
       alert(errorThrown); 
      } 
     }); 

おかげで(再び:-s)。

+1

が、あなたの 'SUCCESS'コールバックが綴られています違う。あなたは末尾の "s"がありません –

+0

ありがとうございました。確かに私は逃した。これで、$ .postメソッドと同じエラーが発生しました。しかしそれは一貫している;) – Jorelie

答えて

1

問題がHTMLにあり、コンテナ要素が見つかりませんでした。 これで両方の方法が機能しています!

Jorelie。ところで

1

- あなたはMVC 3.0でgetJSONを使用することができますが、お使いのコントローラのメソッドがそうのような二番目のパラメータでJSONオブジェクトを返すことがあります。ただ、一見

Json(result, JsonRequestBehavior.AllowGet);