In Javascript I'm calling a function that retrieves data from a data table and converts it to javascriptSerializer, I then use the data in a Javascript chart. Everything works fine the first time round, as soon I change the Dataset selection parameters i.e dates etc, and call Function PopulateChart() again to try to pull a new set of data, I have a problem retrieving it in the javascript. The data and json string is populated correctly on the server but not on the client, the old string of data still exists.
var chartData still shows the old Data, even through the returned serializer.Serialize(rows) shows the correct data on the server
Below is my code and what I'm trying to achieve.
ASPX
var chartData = <%= PopulateChart() %>;
VB
Public Function PopulateChart() As String
''Get Chart Data
Dim daChart As New dsSVTableAdapters.clsChart
Dim dtChart As New dsSV.webV1_ChartsDataTable
Dim drChart As dsSV.webV1_ChartsRow
dtChart = daChart.GetChart(hChartID.Value)
If dtChart.Rows.Count > 0 Then
drChart = dtChart.Rows(0)
hChartName.Value = drChart.Description
HInterval.Value = drChart.Interval
Dim dtData As DataTable
Dim ds As New DataSet()
ds = GetData(4, DateTime.Parse("2012-05-01"), DateTime.Parse("2012-06-30"))
dtData = ds.Tables(0)
Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dtData.Rows
row = New Dictionary(Of String, Object)
For Each col As DataColumn In dtData.Columns
If col.ColumnName = "DateAndTime" Then
Dim dts As DateTime = DateTime.Parse(dr(col).ToString())
row.Add(col.ColumnName, dts.ToString("yyyy-MM-dd hh:mm:ss"))
ElseIf col.ColumnName = "Time" Then
Dim ts As DateTime = DateTime.Parse(dr(col).ToString())
row.Add(col.ColumnName, ts.ToString("hh:mm:ss"))
Else
row.Add(col.ColumnName, dr(col))
End If
Next
rows.Add(row)
Next
serializer.MaxJsonLength = Int32.MaxValue
Return serializer.Serialize(rows)
End If
End Function
var chartData = <%= PopulateChart() %>; will only get evaluated server side at each page load, the <%=....%> is an asp.net wrapper for rendering content in a webpage when and only at a page request. it will not make the PopulateChart() function available to JavaScript on the client side.
you will need to load new data either by ajax calls or reloading the entire page with request parameters indicating what data is to be loaded.
Here is an article on codeproject about asp.net and ajax using jquery.
http://www.codeproject.com/Articles/17203/Using-jQuery-for-AJAX-in-ASP-NET
Related
I have AJax call as below using JS .I am using Knockout JS
var someManager = new AjaxManager('/YYYYYY/XXX/list');
CommonUtils.dispWaitPopup();
// someManager List addLoadCallback()
someManager.addLoadCallback(function (data) {
self.YYYList = ko.observableArray(data.YYYYList);
var viewModel = new ProjectViewModel(data);
ko.applyBindings(viewModel);
CommonUtils.closeWaitPopup();
});
var startDate = new Date();
startDate.setMonth(startDate.getMonth() - 3);
var endDate = new Date();
var param = {
'startDate': moment(startDate).format("YYYY-MM-DD HH:mm:ss"),
'closeDate': moment(endDate).format("YYYY-MM-DD HH:mm:ss"),
};
someManager.request(param);
Datas are fetched from Postgres DB. For particular Numeric field (Example charging rate at back end is having values as 1.00 but Ajax response simply ignore trailing zeros after decimal point by treating it as Numeric . Ironically for some other AJAX call same data (rate ) is returned as String "1.00". I am very much puzzled how same record is returned as Numeric for one Ajax response as well as String for other AJAX call response. Result is coming from same table and same column value.
I need to get the page number in order to extract text from that specific page in a .PDF document. I am using Excel VBA function that makes use of the JSObject from the Acrobat Type Library 10.0
Here is the code snippet and the code hicks up on when I am trying to reference the pageNum property from Doc object. I am trying to avoid the AV Layer and use the PD Layer only, so my macro runs in the background only and doesn't invoke Acrobat Application.
Function getTextFromPDF_JS(ByVal strFilename As String) As String
Dim pdDoc As New AcroPDDoc
Dim pdfPage As Acrobat.AcroPDPage
Dim pdfBookmark As Acrobat.AcroPDBookmark
Dim jso As Object
Dim BookMarkRoot As Object
Dim vBookmark As Variant
Dim objSelection As AcroPDTextSelect
Dim objHighlight As AcroHiliteList
Dim currPage As Integer
Dim strText As String
Dim BM_flag As Boolean
Dim count As Integer
Dim word As Variant
strText = ""
If (pdDoc.Open(strFilename)) Then
Set jso = pdDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
vBookmark = jso.BookMarkRoot.Children
'Add a function call to see if a particular bookmark exists within the .PDF
Set pdfBookmark = CreateObject("AcroExch.PDBookmark")
BM_flag = pdfBookmark.GetByTitle(pdDoc, "Title Page")
If (BM_flag) Then
For i = 0 To UBound(vBookmark)
If vBookmark(i).Name = "Title Page" Then
vBookmark(i).Execute
jso.pageNum
Set pdfPage = pdDoc.AcquirePage(pageNum)
Set objHighlight = New AcroHiliteList
objHighlight.Add 0, 10000 ' Adjust this up if it's not getting all the text on the page
Set objSelection = pdfPage.CreatePageHilite(objHighlight)
If Not objSelection Is Nothing Then
For tCount = 0 To objSelection.GetNumText - 1
strText = strText & objSelection.GetText(tCount)
Next tCount
End If
Exit For
End If
pdDoc.Close
End If
End If
getTextFromPDF_JS = strText
End Function
jso.pageNum = 0; set a page number
pageNo = jso.pageNum; get a page number
edit: 3.3.19
Mmmh, it seems you have to work with AVDoc in order to get the current actual page via jso.pageNum . Also if you work with AVdoc the Acobat window stay hidden in the background. Example:
strFilename = "d:\Test2.pdf"
set avDoc = CreateObject("AcroExch.AVDoc")
If (avDoc.Open(strFilename,"")) Then
Set pdDoc = avDoc.getPDDoc()
Set jso = pdDoc.GetJSObject
pageNo = jso.pageNum
msgbox(pageNo)
end if
I'm trying to fix an old macro working with a function GetData that retrieve the whole page in the response string. (Can't give the real URL here)
Function getDataFor(tva As String) As String
' Early binding, set Tools - Reference - Microsoft XML,v6.0
Dim oDOM As New MSXML2.DOMDocument30
Dim oNodeList As IXMLDOMNodeList
Dim oReq As MSXML2.XMLHTTP
Set oReq = New MSXML2.XMLHTTP
oReq.Open "GET", "https://xxxxxxx.asp?name=" & tva, False
oReq.send
While oReq.readyState <> 4
Wend
Dim response As String
Dim name As String
Dim hasLoginBelspo As String
response = oReq.responseText
Dim token1 As Long
Dim token2 As Long
token1 = InStr(response, "company.name=")
token2 = InStr(response, "company.address=")
On Error GoTo Proceed
name = Mid(response, token1 + 14, token2 - (token1 + 16))
On Error GoTo 0
token1 = InStr(response, "parent.SetLoginInfo")
hasLoginBelspo = Replace(Mid(response, token1 + 28, 5), ",", "")
GoTo Proceed2
Proceed:
name = ""
hasLoginBelspo = ""
Proceed2:
getDataFor = name & "," & hasLoginBelspo
End Function
The concerned page is loaded and the needed data is written between javascript tags:
Here is a copy of what I can find in the source page when I paste the URL in a browser.
<script language="javascript">
var company=new Object();company.number="xxx";company.name="xxx";company.address="xxx";company.zip="xxx";company.city="xxx";parent.SetLoginInfo(company,false,true,"xxx","");
</script>
All the data replaced by xxx is what I need. In the browser, I get it, but with the macro, sometimes those xxx data are empty. It should be because the library used to load the javascript may not be the good one (MSXML2).
Do you have an idea of what I need the change, or what kind of library should I use to be sure the javascript data will be catch?
Thanks a lot
I am reading a text file which contains data to plot a graph in JSP. I am using hidden method and passing the value to the jQuery.
I am able to retrieve the value in jQuery through an alert but when I try to split the value using .split(), the values don't split based on the delimiter specified.
<%
//response.setIntHeader("Refresh", 10);
String jspPath = "C:/Users/Desktop/Out.txt";
BufferedReader reader = new BufferedReader(new FileReader(jspPath));
//BufferedReader br = new InputStreamReader(new FileInputStream(txtFilePath));
StringBuilder sb = new StringBuilder();
String line;
String lastline = "";
while((line = reader.readLine())!= null){
lastline = line;
}
String column3[] = lastline.split("\\*");
%>
<input type="hidden" value="<%=column3[2]%>" id = "filevalue">
jQuery part:
var a = $('#filevalue').text();
var lines = a.split('\n');
alert(lines);
I am referring to this fiddle Link to create the pie chart. Here instead of the hard coded data I am trying to pass the data from the JSP. Since my data is not getting split, i m unable to proceed further.
Please help me to split the data in order to provide it as input to the pie chart.
Two things - try using val() instead of text() to get the value from the hidden field, and you need to quote the "\" in the split command (with an extra "\"):
var a = $('#filevalue').val();
var lines = a.split('\\n');
alert(lines);
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cons, query As String
Dim con As OdbcConnection
Dim adpt As OdbcDataAdapter
'Dim num As Integer
cons = "dsn=Courier; UID=Courier; PWD=123;"
con = New OdbcConnection(cons)
con.Open()
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim ds As DataSet
adpt = New OdbcDataAdapter(query, con)
ds = New DataSet
adpt.Fill(ds, "Courier")
' TextBox1.Text = ds
con.Close()
End Sub
I want to display the name of the employee in Textbox whoos ID is specified in query, what can I do for that?
You should use DataRow but to answer your question, try this.
TextBox1.Text = ds.Tables(0).Rows(0)("Name").ToString()
Since you only want one value back you should skip the dataset and adapter altogether.
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim TempName As String = query.ExecuteScalar
TextBox1.Text = TempName
ExecuteScalar returns the first cell of the first row, that's all you need.
You should read about parameters as well.