json - .ajax call returns undefine in .net? -
i trying build vb.net web app using mongodb database. app needs consuming web service , return json string. used data source 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 ' allow web service called script, using asp.net ajax,'uncomment following line. <system.web.script.services.scriptservice()> _ <system.web.services.webservice(namespace:="http://tempuri.org/")> _ <system.web.services.webservicebinding(conformsto:=wsiprofiles.basicprofile1_1)> _ <global.microsoft.visualbasic.compilerservices.designergenerated()> _ public class webservice_bufferfile inherits system.web.services.webservice dim connectionstring string = "mongodb://localhost" dim client = new mongoclient(connectionstring) <webmethod()> _ public function bufferfile_power(byval userid integer, byval databasename string, byval collection string, byval filedate datetime, byval filename string) string '<scriptmethod(responseformat:=responseformat.json, usehttpget:=false)> _ 'runner = mongo2go.mongodbrunner.start() 'runner.import(strdatabase, strcollection, importfilepath, false) 'mongoimportexport.import("c:\mongodb\bin\", 27017, strdatabase, strcollection, importfilepath, false) dim importfilepath string = "e:\scada\raw\" & databasename & "\" & collection & "\" & format(filedate, "yyyy") & "\buffer\" & filename & "" if file.exists(importfilepath) dim importprocess 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 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 docs.database.dropcollection(usercollection) end if 'dim jsonsearializer new javascriptserializer() 'return jsonsearializer.serialize(jsonstring) 'return 234 return jsonstring end function end class
html page:-
<link href="css/kendo.common.min.css" rel="stylesheet" /> <link href="css/kendo.dataviz.min.css" rel="stylesheet" /> <link href="css/kendo.default.min.css" rel="stylesheet" /> <script type="text/javascript"> </script> <script src="scripts/jquery-1.7.1.min.js"></script> <script src="scripts/kendo.all.min.js"></script> <table border="0" align="center"> <tr> <td class="auto-style1" > <div id="bufferpowerchart" class="k-content"> <div class="powerchart-wrapper" style="margin: auto;"> <div id="powerchart"></div> </div> <script> 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); }); </script> <style scoped> .powerchart-wrapper, .powerchart-wrapper .k-chart { height: 520px; width:850px; } </style> </div> </td> </tr> </table>
any appreciated.
Comments
Post a Comment