【问题标题】:Jquery AJAX to asmx web method get error as responseJquery AJAX 到 asmx Web 方法得到错误作为响应
【发布时间】:2016-05-18 07:59:00
【问题描述】:

好的,我就是这样做的:

客户:

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>

我每次都会收到错误消息:

POST http://localhost:34714/WebService1.asmx/GetChart 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 中放置了断点,但从未达到它。 我做错了什么?

【问题讨论】:

    标签: jquery asp.net ajax web-services asmx


    【解决方案1】:

    // 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]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多