2016-02-08 4 views
0

ОК, так это то, что я делаю:Jquery AJAX для ASMX веб-метод получить ошибку как ответ

клиент:

function AjaxCall(url, method, data, OnSuccessFunction, OnErrorFunction) { 
    var ajaxData = data; 
    ajaxData = JSON.stringify(ajaxData); 
    var ajaxURL = url + "/" + method; 
    $.ajax({ 
     type: "POST", 
     url: ajaxURL, 
     data: ajaxData, 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function() { 
      OnSuccessFunction.apply(this, arguments); 
     }, 
     error: function() { 
      $('.ProgressBar').hide(); 
      OnErrorFunction.apply(this, arguments); 
     } 
    }); 
} 

$(document).ready(function() { 

    AjaxCall("http://localhost:34714/WebService1.asmx", "GetChart", { filename: 'excel-demo.xlsx', sheet: 'chart_param' }, GetTradingViewSuccess, GetTradingViewError) 

}); 

var GetTradingViewSuccess = function (data) { 

} 

var GetTradingViewError = function (jqXHR, textStatus, errorThrown) { 

} 

ASMX:

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.OleDb; 
using System.Linq; 
using System.Web; 
using System.Web.Script.Services; 
using System.Web.Services; 
using WebApplication2.Classes; 

namespace WebApplication3 
{ 
    /// <summary> 
    /// Summary description for WebService1 
    /// </summary> 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [System.ComponentModel.ToolboxItem(false)] 
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService] 
    public class WebService1 : System.Web.Services.WebService 
    { 
     [System.Web.Script.Services.ScriptMethod()] 
     [WebMethod] 
     public string add() 
     { 
      return "sd"; 
     } 

     [WebMethod(EnableSession = true)] 
     public Chart GetChart(string filename, string sheet) 
     { 
      Chart c = new Chart(); 
      //do something 

      return c; 
     } 
    } 
} 

веб-конфигурации:

<?xml version="1.0"?> 

<configuration> 
    <system.web> 
     <webServices> 
     <protocols> 
      <add name="HttpGet"/> 
      <add name="HttpPost"/> 
     </protocols> 
     </webServices> 

     <compilation debug="true" targetFramework="4.5.1" /> 
     <httpRuntime targetFramework="4.5.1" /> 
    </system.web> 

</configuration> 

и я получаю каждое сообщение об ошибке :

http://localhost:34714/WebService1.asmx/GetChart POST 500 (Внутренняя ошибка сервера ) отправить @ Jquery-1.7.2.min.js: 4f.extend.ajax @ JQuery-1.7.2.min.js: 4AjaxCall @ common.js : 5 (анонимная функция) @ chart.html: 15o @ jquery-1.7.2.min.js: 2p.fireWith @ jquery-1.7.2.min.js: 2e.extend.ready @ jquery-1.7. 2.min.js: 2c.addEventListener.B @ JQuery-1.7.2.min.js: 2 errorThrown "Внутренняя ошибка сервера"

я ставлю точку останова в ASMX файл - GetChart WebMethod, но никогда не достиг Это. что я делаю неправильно?

ответ

2

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

раскомментируйте строки ниже.

// [System.Web.Script.Services.ScriptService]

становится

[System.Web.Script.Services.ScriptService]