.ajax call returns undefine in .net?-Collection of common programming errors

I am trying to build vb.net web app by using mongodb as database. App needs consuming web service and return JSON string. which is used as data source for Kendo UI chart.

My web service:-

    Imports MongoDB.Bson
    Imports MongoDB.Driver
    Imports MongoDB.Driver.Builders
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Web.Script.Services
    'Imports System.Web.Script.Serialization
    Imports System.ComponentModel
    Imports System.IO
    Imports AjaxControlToolkit

    ' To allow this Web Service to be called from script, using ASP.NET AJAX,'uncomment the following line.
     _
     _
     _
     _
Public Class WebService_BufferFile
    Inherits System.Web.Services.WebService
    Dim connectionString As String = "mongodb://localhost"
    Dim client = New MongoClient(connectionString)
     _
    Public Function BufferFile_Power(ByVal UserId As Integer, ByVal DataBaseName As String, ByVal Collection As String, ByVal FileDate As DateTime, ByVal FileName As String) As String
    ' _
    'runner = Mongo2Go.MongoDbRunner.Start()
    'runner.Import(strDatabase, strCollection, ImportFilePath, False)
    'MongoImportExport.Import("C:\MongoDB\bin\", 27017, strDatabase, strCollection, ImportFilePath, False)

    Dim ImportFilePath As String = "E:\SCADA\RAW\" & DataBaseName & "\" & Collection & "\" & Format(FileDate, "yyyy") & "\Buffer\" & FileName & ""
    If File.Exists(ImportFilePath) Then
        Dim ImportProcess As New Process()
        ImportProcess.StartInfo.UseShellExecute = True
        ImportProcess.StartInfo.CreateNoWindow = True
        ImportProcess.StartInfo.WorkingDirectory = "C:\MongoDB\bin"
        ImportProcess.StartInfo.FileName = "mongoimport.exe"
        ImportProcess.StartInfo.Arguments = " --db " & DataBaseName & " --collection " & Collection & "_" & Format(FileDate, "yyMMdd") & "_" & UserId & " --type csv --file " & ImportFilePath & " --headerline"
        ImportProcess.Start()
        ImportProcess.WaitForExit(1500)
        ImportProcess.Dispose()
    Else
        Return 0
        Exit Function
    End If
    Dim server = client.GetServer()
    Dim database = server.getDatabase(DataBaseName)
    Dim UserCollection = Collection & "_" & Format(FileDate, "yyMMdd") & "_" & UserId
    Dim Docs As MongoCursor = database.GetCollection(UserCollection).FindAll()
    Docs.SetSortOrder(SortBy.Ascending("timestamp"))
    Docs.SetFields(Fields.Include("timestamp", "converter_UL1", "converter_UL2", "converter_UL3", "converter_I1", "converter_I2", "converter_I3").Exclude("_id"))
    Docs.SetLimit(3000)
    Dim JsonString = Docs.ToJson
    If Docs.Count > 0 Then
        Docs.Database.DropCollection(UserCollection)
    End If
    'Dim jsonSearializer As New JavaScriptSerializer()
    'Return jsonSearializer.Serialize(JsonString)
    'Return 234
    Return JsonString

    End Function
End Class

HTML Page:-




 


function createPowerChart() { $.ajax( { type: ‘POST’, url: ‘/WebService_BufferFile.asmx/BufferFile_Power’, contentType: ‘application/json; charset=utf-8’, dataType: ‘json’, data: ‘{“UserId”:174,”DataBaseName”:”ChitraDurga”,”Collection”:”NSLHK-06″,”FileDate”:”05/05/2013″,”FileName”:”NSLHk-06_b130505_1819.txt”}’, async: false, success: OnSuccess, error: OnError }); function OnSuccess(PowerChartData) { alert(PowerChartData.d); var PowerChartDataSource = JSON.parse(PowerChartData.d); $(“#PowerChart”).kendoChart({ title: { text: “Power” }, legend: { visible: true, position: “bottom” }, dataSource: PowerChartDataSource, series: [{ type: “line”, field: “converter_UL1”, name: “converter_UL1” }, { type: “line”, field: “converter_UL2”, name: “converter_UL2” }, { type: “line”, field: “converter_UL3”, name: “converter_UL3” }, { type: “line”, field: “converter_I1”, name: “converter_I1” }, { type: “line”, field: “converter_I2”, name: “converter_I2” }, { type: “line”, field: “converter_I3”, name: “converter_I3” }], categoryAxis: { field: “timestamp”, labels: { rotation: -5 }, majorGridLines: { visible: true } }, valueAxis: { max: 1500, line: { visible: true }, majorUnit:100, minorGridLines: { visible: true } }, tooltip: { visible: true, template: “#= series.name #: #= value #” } }); } function OnError(msg) { alert(‘Error = ‘ + msg.d); } } $(document).ready(function () { //debugger; setTimeout(function () { createPowerChart(); }, 500); }); .PowerChart-wrapper, .PowerChart-wrapper .k-chart { height: 520px; width:850px; }

Any help would be appreciated.

Originally posted 2013-11-09 22:52:19.