maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Get javascript from site and run them (https://talk.maemo.org/showthread.php?t=71836)

Lullen 2011-04-05 19:57

Get javascript from site and run them
 
I am currently doing a program for a site which need me to run a certain javascript. The script do I get from a HTTP 200 response. My problem is that I have never done javascripting so I do not really know how this works, I could guess that you would use the QScriptEngine to process it.

But the bigger problem I have is that when I get the response with the script and runs it, it should try to communicate with the server. This is becuase in the <script type="text/javascript"> there is a function filter which looks like this:

Code:

function filter() {
var query = "userId=11111&daysBack=" + $("#daysBack").val();
$("#chartContainer").load("/statistics/typedistributionchart?" + query);
}

I have been running wireshark to see all the packets thats being transmitted/recieved. But all I see is a ACK and then nothing more. So what I think is that this $("#chartContainer").load() stuff is already on my computer. But if so how do I access this and what datatype is it??

Yours,

demolition 2011-04-05 22:18

Re: Get javascript from site and run them
 
Are these scripts designed to be run on Maemo or even mobile devices? This isn't really a js forum but everyone round here will help where we can.

I'm unsure what you want anyone to do. Please would you re-ask your question(s) in a really simple way so it's clear what you want
- say what the situ is, in each case
- describe the expected outcome
- describe the actual outcome
- reiterate what you want help with, including any ideas you have for the problem.
Doing it in this neo-bug-report way means you'll get a result quickly.

mr id 2011-04-05 22:40

Re: Get javascript from site and run them
 
Quote:

Originally Posted by Lullen (Post 982635)
But the bigger problem I have is that when I get the response with the script and runs it, it should try to communicate with the server. This is becuase in the <script type="text/javascript"> there is a function filter which looks like this:

Code:

function filter() {
var query = "userId=11111&daysBack=" + $("#daysBack").val();
$("#chartContainer").load("/statistics/typedistributionchart?" + query);
}

I have been running wireshark to see all the packets thats being transmitted/recieved. But all I see is a ACK and then nothing more. So what I think is that this $("#chartContainer").load() stuff is already on my computer. But if so how do I access this and what datatype is it??

Yours,

Looks like fairly standard JavaScript JQuery running in a browser :
var query
is a dynamically built string where
$("#daysBack").val()
is most likely the value inputted or held in the html form element with 'id="daysBack"'

$("#chartContainer").load("/statistics/typedistributionchart?" + query);
is then calling the url query and displaying the returned HTML in a visual element with an 'id=chartContainer'

If I were you I'd look at what:
http://THE_SITE/statistics/typedistr...111&daysBack=2
returns, assuming a valid user ID of course.

Does it return HTML? Will you need to parse out the bits you want from this markup? Does the site offer a cleaner way of getting this data?

Lullen 2011-04-06 06:43

Re: Get javascript from site and run them
 
@Demolition: I know this is not a js forum but I am building the app in Qt and it will be for maemo/meego :)

Quote:

Originally Posted by mr id (Post 982716)
Looks like fairly standard JavaScript JQuery running in a browser :
var query
is a dynamically built string where
$("#daysBack").val()
is most likely the value inputted or held in the html form element with 'id="daysBack"'

$("#chartContainer").load("/statistics/typedistributionchart?" + query);
is then calling the url query and displaying the returned HTML in a visual element with an 'id=chartContainer'

If I were you I'd look at what:
http://THE_SITE/statistics/typedistr...111&daysBack=2
returns, assuming a valid user ID of course.

Does it return HTML? Will you need to parse out the bits you want from this markup? Does the site offer a cleaner way of getting this data?

From http://THE_SITE/statistics/typedistr...111&daysBack=2 I do get back a HTML file. That is the one containing the script. What is happening when I send the http://THE_SITE/statistics/typedistr...111&daysBack=2 to the server (from browser) is that i get a pop-up with a pie diagram wich shows me how much, in percent, I have been doing each training type.

here is a picture

I was in contact with the site owner before and his real api was quite limited to his own apps which were limited too. So this is the only way to go.

I figured out how to save the packets to a txt file so here is the packets from GET to response. After this packets a new GET comes(which was me changing daysBack).
http://pastebin.com/YjJ7Db27

Hope you guys understand this now! :)

Yours,

mr id 2011-04-06 07:16

Re: Get javascript from site and run them
 
The site is returning the javascript conifguration for building the diagram in a library called Highcharts. The necessary js includes for this library will likely be at the top of html page that first loads. Look for highcharts.js or similar, it's a great charting library but does it run in Qt?

You could parse out the dataset and draw the charts yourself of course. Lmk if it wasn't clear to you where that data is.

Lullen 2011-04-06 07:31

Re: Get javascript from site and run them
 
Thanks, I will look into it!
I did not mean the site was running Qt but my application that need the charts does :)

mr id 2011-04-06 07:34

Re: Get javascript from site and run them
 
Quote:

Originally Posted by Lullen (Post 982868)
Thanks, I will look into it!
I did not mean the site was running Qt but my application that need the charts does :)

Fully understand that, sorry if it wasn't clear. If the charting doesn't run in your app you'll need to parse out the values and render the chart yourself.

cheers


All times are GMT. The time now is 00:37.

vBulletin® Version 3.8.8