Inserisci qui il codice...

Hello to all,
 I'm not good with js because I start developing a few months ago and I 
have a lot to learn but I'm trying to understand if it's possible to do 
this: 


   - Create a service (for example in php that, with a given url, respond 
   with a descriprion of website (show test-2.php)
   - TW Widget that call this service and include the result in TW feed or 
   if it's not possible create a new tiddler with the returned information

*It's possible what i'm trying to do? *

*test-2.php*
<?php
  header('Content-type: text/html');
  header('Access-Control-Allow-Origin: *');
  $url = $_GET['url'];

  $tags = get_meta_tags($url);
  $description = $tags["description"];
  echo '<br /> url: ';
  print_r($url);
  echo '<br /> description: ';
  print_r($description);
?>

Tw Widget *$:/paulin/demo/getdata.js*:

/*\
title: $:/paulin/demo/getdata.js
type: application/javascript
module-type: macro


<<getdata "url">>


\*/
(function(){


/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";


/*
 * Testing: get data with ajax
 */


exports.name = "getdata";


exports.params = [
 { name: "url" }
];


/*
 * Run the macro
 */
exports.run = function(url) {
 var url = url || "None";


        function ajax(url) {
          return new Promise(function(resolve, reject) {
            var xhr = new XMLHttpRequest();
            xhr.onload = function() {
              resolve(this.responseText);
            };
            xhr.onerror = reject;
            xhr.open('GET', url);
            xhr.send();
          });
        }




var ret_val;
ajax('./test-2.php?url='+url).then(function(result) {
          console.log('**** > '+result);
   ret_val = result;
          return result;
        }).catch(function() {
          console.log('Error');
   ret_val = "An error occurred";
          return "An error occurred";
        });
console.log('----> '+ret_val);
return ret_val;        
};


})();

Thanks.
Paulin

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/92bbc28b-3b5f-4546-a0dd-544024690121%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to