2017-03-23 154 views
0

我收到內部錯誤500,當我從JQuery調用,否則。請幫助!!!Webservice返回從JQuery調用返回內部錯誤500

JQuery的通話

$.ajax({ 
        type: "POST", 
        url: "myWebService.asmx/getnpsTrend", 
        data: jsonData, 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: OnSuccess_, 
        error: OnErrorCall_ 
       }); 

Webservice的方法:

 [WebMethod] 
     [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)] 
     public List<ChartDatasets> getnpsTrend(string region, string client, string product) 
     { 
     <code> 
     } 

我已經試過除了靜態提供一切可能的解決方案:

  1. Enabled get

  2. Reconfigured Config file

更多的背景...

  • 我使用chart.js之顯示圖形
  • 爲了使圖表數據的動態,我使用WebService給我以json格式輸入數據。 Here是參考。
  • 如果我直接調用webservice,這可以很好地工作。所以我想知道如果在JQuery調用提供的URL是錯誤的!嘗試過不同的組合,但沒有任何工作! :(

編輯: 完整的jQuery代碼

<script> 

     $(document).ready(function() { 
      $("#btn_line_chart").on('click', function() { 
       var fil_reg = $("#ddlRegion").val(); 
       var fil_cli = $("#ddlClient").val(); 
       var fil_prd = $("#ddlProduct").val(); 

       console.log("Inside function"); 
       console.log(fil_reg); 
       var jsonData = JSON.stringify({ 
        jsn_reg: fil_reg, 
        jsn_cli: fil_cli, 
        jsn_prd: fil_prd 
       }); 


       $.ajax({ 
        type: "POST", 
        url: "myWebService.asmx/getnpsTrend", 
        data: jsonData, 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: OnSuccess_, 
        error: OnErrorCall_ 
       }); 

       function OnSuccess_(reponse) { 
        var aData = reponse.d; 
        var aLabels = aData[0]; 
        var aDatasets1 = aData[1]; 
        var aDatasets2 = aData[2]; 

        var data = { 
         labels: aLabels, 
         datasets: [{ 
          label: "My First dataset", 
          fillColor: "rgba(220,220,220,0.2)", 
          strokeColor: "rgba(220,220,220,1)", 
          pointColor: "rgba(220,220,220,1)", 
          pointStrokeColor: "#fff", 
          pointHighlightFill: "#fff", 
          pointHighlightStroke: "rgba(220,220,220,1)", 
          data: aDatasets1 
         }, 
         { 
          label: "My Second dataset", 
          fillColor: "rgba(151,187,205,0.2)", 
          strokeColor: "rgba(151,187,205,1)", 
          pointColor: "rgba(151,187,205,1)", 
          pointStrokeColor: "#fff", 
          pointHighlightFill: "#fff", 
          pointHighlightStroke: "rgba(151,187,205,1)", 
          data: aDatasets2 
         }] 
        }; 

        var ctx = $("#myChart").get(0).getContext('2d'); 
        ctx.canvas.height = 300; // setting height of canvas 
        ctx.canvas.width = 500; // setting width of canvas 
        var lineChart = new Chart(ctx).Line(data, { 
         bezierCurve: false 
        }); 
       } 
       function OnErrorCall_(repo) { 
        alert("Woops something went wrong, pls try later !"); 
       } 
      }); 
     }); 

    </script> 

回答

0

製作跟隨webscript變化

[System.Web.Script.Services.ScriptService] // add top of Class file 
    public class myWebService: System.Web.Services.WebService 
    { 
     [WebMethod(EnableSession = true)] 
     public List<ChartDatasets> getnpsTrend(string region, string client, string product) 
     { 
     //Check if we get All Parameters from Ajax function i.e region, client and product 

     // Code 

     } 
} 

然後在阿賈克斯功能

$.ajax({ 
      url: '../myWebService.asmx/getnpsTrend', 
      data: "{'region': '" + regionvalue + "'}, 'client': '" + clientvalue + "','product': '" + productvalue + "'", 
      dataType: "json", 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      success: function (data) 
      { 
       if (data != null) 
       { 
        // use data.d value 

       } 
      }, 
      error: function (data) 
      { 
       alert("Error message "); 
      } 
     }); 
+0

感謝您的迴應!不幸的是,我已經實施了您提到的所有更改。它還沒有工作!我用完整的代碼更新了我的問題。如果您發現其他任何遺漏,請讓我知道。謝謝! – Linda

+0

而不是數據:jsonData嘗試傳遞數據:「{'region':''+ regionvalue +''},'client':''+ clientvalue +'','product':'」+ productvalue +「'」 } – Ricky007

+0

仍然是一樣的錯誤:( – Linda