accessing database from inside .js file - javascript

I am working on 2 seperate .js files 1)jquery.skitter.js 2)gauge.js
I have a speedometer type gauge which displays a rating.
I need to fetch the rating from a database and put it in the gauge and change it dynamically
data-onready="setInterval( function() { Gauge.Collection.get('gauge1').setValue({Insert django function here});}, 4000);"
I am using django as back-end and this code is placed inside the skitter.js file's functions.
The problem I am facing is that everytime the skitter is initialised it places images in random order. I have to get the name of the image( which i get using this.settings.label_atual) but how to i go about the next step i.e sending the value of label_atual to the sql query to fetch the ratings ?

Related

Trouble understanding the flow of data in a PHP file which uses both server side and client side scripting

I am creating a wordpress plugin where a shortcode can be added to a page which when loaded will display a chart for a chosen user, using that user's data in the wordpress database.
Currently, when the page is loaded, a PHP function executes a couple of SQL queries to create 2 arrays that are then passed as JSON objects to some javascript that dynamically displays two drop-down lists (populated by appropriate data from the arrays). This all works fine and the drop downs display perfectly.
Elsewhere in my PHP file I have php functions that generate charts using charts.js for a given user after it is passed a user ID number. This code also works well when run separately, displaying a graph on the webpage.
My issue is that I need my PHP file to be able to access the user that is chosen from the drop-down list and pass it to another PHP function to generate the graph and display it under the drop-downs.
Now I know JS is client side and PHP is server side. Therefore the only way to pass a JS variable to the PHP is to make an AJAX call. I have this working following the drop-down selection, but the problem is that the PHP file has already been executed. So even though the php file receives the chosen user data in a php variable, which is passed to the graph creation PHP functions, the web page will not update with the graph as the php file has already been executed.
My question is, what possible options do I have here?
My aim is to have a shortcode that displays drop downs and once the user selects a person from the list, the charts for that user are displayed underneath.
Do I need to rewrite my php graph creation functions (that have SQL queries and subsequent PHP calculations) so they are written in pure JS and executed straight after the drop-down select form is submitted (removing the requirement for having the chosen user data in a php variable),  or is there a way that I can still use my graph creating PHP functions that reside in the same PHP file so they display the graph under the drop down once a person is selected from the list?

how to upload canvas image using struts2 [duplicate]

I need to retrieve rows in database with a image saved in byte array. How do I display the image using Strut2?
I have displayed it by using custom result. I passed the id and make an action search for it in the database. My problem is how to invoke this several times? I have an action that retrieve all the rows. How to call display image action from the list action? Or is there a better way to achieve this?
JAVA
My action has an list of the objects I want to show on JSP.
JSP
First way: I use iterator tag and on each iteration I want to display the image which is in byte array. I want call the action to retrieve the image here.
Second way: I tried this post and it is not working for me.
<img src="data:image/jpg;base64, <s:property value="imageData"></s:property> />" >
Image data is the image in string.
To retrieve rows in database there's many ways but all of them utilize JDBC API. You can map the object as an image array containing bytes or blob or clob data that you persist in the database.
Displaying the images required to send it to the browser. In the Struts2 there's a stream result type that could be used to output the image data to the browser.
Or use the Servlet API to transmit the data on the JSP similar like in How to send and display image from action class to JSP in Struts 2 answer.
Combining the experience from the answers that you already enlighten in the question to stringify data you may achieve suitable results.

Read data from Excel file using Apex in Salesforce

I have a requirement where we need to parse the excel file and insert the data in one of the object using apex. This excel file contains multiple sheets. We need to read the data from multiple sheets (as of now one sheet is also fine) and upload the data.
Please help me with a solution.
I would suggest to provide more details about where the question starts and ends since it implies you already have the data available in your apex class but also doesn't include any information about the type/format you have it loaded as etc.
Here is a concept of what you might do (using a visualforce page and an apex controller) in case you are trying to figure out where to start:
1) Use apex:inputFile to load up the file into your apex controller (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputFile.htm)
Note: You can only upload files <= 10Mb this way
2) I would then send the uploaded object from my apex controller back to visualforce
One way to do this is to have a public property in the apex (e.g. MyExcelFile), and have your form trigger an apex:actionFunction to rerender a hidden component whose content is {!MyExcelFile} + run your parsing logic
(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_display_field_values.htm)
(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionFunction.htm)
3) Then I could parse it using whatever javascript library I felt like in my visualforce page (How to parse Excel file in Javascript/HTML5)
4) From there it is just a matter of calling a function in your apex controller which does the insert/update/whatever operation(s) and passing the params
(https://eltoro.secure.force.com/PassingParametersFromVisualforcePageToApexControllerViaApexParam)

How to request dynamically created JS files using AngularJS

We have a lot of these small sets of data that populates our select dropdowns in our view. For example, gender, countries, shirt sizes, country contact codes, etc..
These data sets don't normally change so I'm thinking what would be the best option to retrieve these data to our views.
Create endpoints for them. So I would have something like below
http://dom.com/countries
http://dom.com/genders
http://dom.com/shirt_sizes
Problem is I would make several "expensive" http requests just to retrieve these information.
Create a module and hardcode these values in a service
angular.module('OptionsModule')
.factory('options', function() {
return {
genders: ['M','F'],
// others
}
}
Problem is some options I still need to load from the database. For example,
the countries list. So I need a way to dynamically create this module from the server
I kinda prefer option #2. But how do you generate js files dynamically from php and how do I request for it using angularjs?
Mix of your two points is good. Use hardcoded values for small lists and backend requests for long/DB-placed data.
You need not send js file, you just send JSON object. In PHP you get it by json_encode and in JS you get your JS object (you need nothing).

How to retrieve images from database using jquery and servlet

I need to retrieve the images which is stored in my oracle 11g R2 database. I'm trying to retrive the images using Jquery and servlet, And placing into the css division. But I'm a newbie in this. I know using json objects we can do this stuff. Please anyone tell me how to do
Make a request that returns a list of the names of all images (so that you know what to retrieve)
Make a servlet that serves images - gets the name as GET parameter, looks it up in the database (e.g. via JDBC) and streams the result back into the response.getOutputStream(), and set the correct content type

Categories

Resources