jacky brown February 2016

Jquery AJAX to asmx web method get error as response

OK, so this is what I do:

client:

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)
              

Answers


zgood February 2016

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

Uncomment the Line below that.

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

becomes

[System.Web.Script.Services.ScriptService]

Post Status

Asked in February 2016
Viewed 1,722 times
Voted 11
Answered 1 times

Search




Leave an answer