jQuery的AJAX来ASMX web方法得到错误的反应 [英] Jquery AJAX to asmx web method get error as response

查看:303
本文介绍了jQuery的AJAX来ASMX web方法得到错误的反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,所以这是我做的:

OK, so this is what I do:

客户端:

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;
        }
    }
}

web配置:

<?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>

和我得到的每一次错误消息:

and I get every time error message:

的http://本地主机: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:150 @ 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内部服务器错误

POST http://localhost:34714/WebService1.asmx/GetChart 500 (Internal Server Error)send @ jquery-1.7.2.min.js:4f.extend.ajax @ jquery-1.7.2.min.js:4AjaxCall @ Common.js:5(anonymous function) @ 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 "Internal Server Error"

我把打破ASMX文件点 - GetChart的webmethod,但从来没有达到它。
我究竟做错了什么?

I put break point in asmx file - GetChart webmethod, but never reached it. what am i doing wrong?

推荐答案

//要允许此Web服务从脚本调用,使用ASP.NET AJAX,取消注释以下行。

取消注释下面的线路。

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

变为

[System.Web.Script.Services.ScriptService]

这篇关于jQuery的AJAX来ASMX web方法得到错误的反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆