{"id":883,"date":"2022-08-30T15:08:46","date_gmt":"2022-08-30T15:08:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/ajax-call-returns-undefine-in-net-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:46","modified_gmt":"2022-08-30T15:08:46","slug":"ajax-call-returns-undefine-in-net-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ajax-call-returns-undefine-in-net-collection-of-common-programming-errors\/","title":{"rendered":".ajax call returns undefine in .net?-Collection of common programming errors"},"content":{"rendered":"<p>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.<\/p>\n<p>My web service:-<\/p>\n<pre><code>    Imports MongoDB.Bson\n    Imports MongoDB.Driver\n    Imports MongoDB.Driver.Builders\n    Imports System.Web.Services\n    Imports System.Web.Services.Protocols\n    Imports System.Web.Script.Services\n    'Imports System.Web.Script.Serialization\n    Imports System.ComponentModel\n    Imports System.IO\n    Imports AjaxControlToolkit\n\n    ' To allow this Web Service to be called from script, using ASP.NET AJAX,'uncomment the following line.\n     _\n     _\n     _\n     _\nPublic Class WebService_BufferFile\n    Inherits System.Web.Services.WebService\n    Dim connectionString As String = \"mongodb:\/\/localhost\"\n    Dim client = New MongoClient(connectionString)\n     _\n    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\n    ' _\n    'runner = Mongo2Go.MongoDbRunner.Start()\n    'runner.Import(strDatabase, strCollection, ImportFilePath, False)\n    'MongoImportExport.Import(\"C:\\MongoDB\\bin\\\", 27017, strDatabase, strCollection, ImportFilePath, False)\n\n    Dim ImportFilePath As String = \"E:\\SCADA\\RAW\\\" &amp; DataBaseName &amp; \"\\\" &amp; Collection &amp; \"\\\" &amp; Format(FileDate, \"yyyy\") &amp; \"\\Buffer\\\" &amp; FileName &amp; \"\"\n    If File.Exists(ImportFilePath) Then\n        Dim ImportProcess As New Process()\n        ImportProcess.StartInfo.UseShellExecute = True\n        ImportProcess.StartInfo.CreateNoWindow = True\n        ImportProcess.StartInfo.WorkingDirectory = \"C:\\MongoDB\\bin\"\n        ImportProcess.StartInfo.FileName = \"mongoimport.exe\"\n        ImportProcess.StartInfo.Arguments = \" --db \" &amp; DataBaseName &amp; \" --collection \" &amp; Collection &amp; \"_\" &amp; Format(FileDate, \"yyMMdd\") &amp; \"_\" &amp; UserId &amp; \" --type csv --file \" &amp; ImportFilePath &amp; \" --headerline\"\n        ImportProcess.Start()\n        ImportProcess.WaitForExit(1500)\n        ImportProcess.Dispose()\n    Else\n        Return 0\n        Exit Function\n    End If\n    Dim server = client.GetServer()\n    Dim database = server.getDatabase(DataBaseName)\n    Dim UserCollection = Collection &amp; \"_\" &amp; Format(FileDate, \"yyMMdd\") &amp; \"_\" &amp; UserId\n    Dim Docs As MongoCursor = database.GetCollection(UserCollection).FindAll()\n    Docs.SetSortOrder(SortBy.Ascending(\"timestamp\"))\n    Docs.SetFields(Fields.Include(\"timestamp\", \"converter_UL1\", \"converter_UL2\", \"converter_UL3\", \"converter_I1\", \"converter_I2\", \"converter_I3\").Exclude(\"_id\"))\n    Docs.SetLimit(3000)\n    Dim JsonString = Docs.ToJson\n    If Docs.Count &gt; 0 Then\n        Docs.Database.DropCollection(UserCollection)\n    End If\n    'Dim jsonSearializer As New JavaScriptSerializer()\n    'Return jsonSearializer.Serialize(JsonString)\n    'Return 234\n    Return JsonString\n\n    End Function\nEnd Class\n<\/code><\/pre>\n<p>HTML Page:-<\/p>\n<pre><code>\n\n\n \n\n\n<\/code><\/pre>\n<table border=\"0\" align=\"center\">\n<tr>\n<td class=\"auto-style1\">function createPowerChart() { $.ajax( { type: &#8216;POST&#8217;, url: &#8216;\/WebService_BufferFile.asmx\/BufferFile_Power&#8217;, contentType: &#8216;application\/json; charset=utf-8&#8217;, dataType: &#8216;json&#8217;, data: &#8216;{&#8220;UserId&#8221;:174,&#8221;DataBaseName&#8221;:&#8221;ChitraDurga&#8221;,&#8221;Collection&#8221;:&#8221;NSLHK-06&#8243;,&#8221;FileDate&#8221;:&#8221;05\/05\/2013&#8243;,&#8221;FileName&#8221;:&#8221;NSLHk-06_b130505_1819.txt&#8221;}&#8217;, async: false, success: OnSuccess, error: OnError }); function OnSuccess(PowerChartData) { alert(PowerChartData.d); var PowerChartDataSource = JSON.parse(PowerChartData.d); $(&#8220;#PowerChart&#8221;).kendoChart({ title: { text: &#8220;Power&#8221; }, legend: { visible: true, position: &#8220;bottom&#8221; }, dataSource: PowerChartDataSource, series: [{ type: &#8220;line&#8221;, field: &#8220;converter_UL1&#8221;, name: &#8220;converter_UL1&#8221; }, { type: &#8220;line&#8221;, field: &#8220;converter_UL2&#8221;, name: &#8220;converter_UL2&#8221; }, { type: &#8220;line&#8221;, field: &#8220;converter_UL3&#8221;, name: &#8220;converter_UL3&#8221; }, { type: &#8220;line&#8221;, field: &#8220;converter_I1&#8221;, name: &#8220;converter_I1&#8221; }, { type: &#8220;line&#8221;, field: &#8220;converter_I2&#8221;, name: &#8220;converter_I2&#8221; }, { type: &#8220;line&#8221;, field: &#8220;converter_I3&#8221;, name: &#8220;converter_I3&#8221; }], categoryAxis: { field: &#8220;timestamp&#8221;, labels: { rotation: -5 }, majorGridLines: { visible: true } }, valueAxis: { max: 1500, line: { visible: true }, majorUnit:100, minorGridLines: { visible: true } }, tooltip: { visible: true, template: &#8220;#= series.name #: #= value #&#8221; } }); } function OnError(msg) { alert(&#8216;Error = &#8216; + msg.d); } } $(document).ready(function () { \/\/debugger; setTimeout(function () { createPowerChart(); }, 500); }); .PowerChart-wrapper, .PowerChart-wrapper .k-chart { height: 520px; width:850px; }<\/td>\n<\/tr>\n<\/table>\n<p>Any help would be appreciated.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:52:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 &#8216;Imports System.Web.Script.Serialization Imports System.ComponentModel Imports System.IO Imports AjaxControlToolkit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=883"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/883\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}