Tasker based Javascript Can't use JQuery

347 views
Skip to first unread message

Mr Dini

unread,
Jul 9, 2016, 12:00:32 PM7/9/16
to Tasker
Hi all!

I wrote a parser, which downloads a HTML file and convert it as normal text. And finally flash it as a Toast. For that, I used Javascript, because I think, it is a bit faster than the simple Task option.

The code works, but I Can't found any way to download the html file directly from the JS code. So I tried to use JQuery and wrote this code part to download the HTML and load it to a Global Tasker variable:

$.get('http://example.com/index.html', function( data ){
setGlobal('%Data', data);
}, 'html')

And I selected JQuery from the Libraries at the Javascriptlet page from the magnifying glass's list. But it not works... :(

Is the JQuery works in Tasker? Or just the Tasker based codes (like setGlobal) not works between a JQuery code part?

What's wrong?

Thanks for Your answer!

--
Dan

Mr Dini

unread,
Jul 13, 2016, 5:10:23 AM7/13/16
to tas...@googlegroups.com

Nobody Can help me?

Now I am using a shell and the wget command, but the JQuery would be nice for other operations too. Is it workable?

Thanks again!

Pent

unread,
Jul 13, 2016, 9:06:22 AM7/13/16
to Tasker
It's unclear to me from your description what works and what doesn't work.

I don't know JS or Jquery so can't help you there. Try tk.setGlobal if you're using a webview.

Also show a JS dialog with the downloaded text first to check that bit is working.

Pent

Mr Dini

unread,
Jul 13, 2016, 12:28:44 PM7/13/16
to tas...@googlegroups.com

I want to parse a json file. But I download it from the internet. Yes, I Can use the HTTP Get and the %HTTPD variable, but I want to do this via a single JS code.

Now, I am using shell, like this:

shell('wget http://path/to.json',3);

But if the JQuery is workable it would be better than this way. Because the JQuery has a $.get "function", but I Can't use it, because the Tasker's Javascript Can't use the JQuery which in the Libraries part of the Javascriptlet.

So... My question is why not works the JQuery?

Juergen Gruen

unread,
Jul 13, 2016, 2:01:29 PM7/13/16
to Tasker

Hi!


The code works, but I Can't found any way to download the html file directly from the JS code.

So I tried to use JQuery and wrote this code part to download the HTML and load it to a Global Tasker variable:

$.get('http://example.com/index.html', function( data ){
setGlobal('%Data', data);
}, 'html')


Use try/catch to get an error message:

try
{

    $.get('http://example.com/index.html', function( data ){setGlobal('%Data', data);}, 'html')
}
catch(error)
{
    alert(error);
}

You do not need a global variable. Just parse the result of your http-request directly with the JSON-object: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON


Juergen.

Mr Dini

unread,
Jul 14, 2016, 4:59:27 AM7/14/16
to tas...@googlegroups.com

Hi!

Yes, I tried it, but not worked. I think it is an ajax feature too which not works below Tasker javascript.

> Use try/catch to get an error message:
>
> try
> {
>
>     $.get('http://example.com/index.html', function( data ){setGlobal('%Data', data);}, 'html')
> }
> catch(error)
> {
>     alert(error);
> }

I tried it, but not worked, and nothing shown at the error output. But the global %Data is blank.

Ps: I think it isn't alert, it is flash.

The global variable is just a test.

> You do not need a global variable. Just parse the result of your http-request directly with the JSON-object: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON

Yes, I know that, but it is just a part of a function. I want to parse the data at a second part of the code.

Thanks!

Juergen Gruen

unread,
Jul 14, 2016, 3:49:36 PM7/14/16
to Tasker
Hi,

this scriptlet works fine here:

var url = "http://date.jsontest.com";

var http = new XMLHttpRequest();
http
.open("GET", url, false);
http
.send();
 
if (http.status == 200)
   
{
     
var json = JSON.parse(http.responseText);
     alert
("Now it is " + json.time);
   
}
else
   
{
     alert
("HTTP-Error...");
   
}



PS: "alert" is the javascript method. "flash" invokes the tasker action...

Juergen.

Mr Dini

unread,
Jul 15, 2016, 4:16:54 AM7/15/16
to tas...@googlegroups.com

Many thanks, it works!

I think, I missed the .send... :)

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/MHP46EEVq5M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages