How can I build a stable js-macro (that does not produce a "network error" )

65 views
Skip to first unread message

Jan

unread,
Jul 25, 2019, 12:15:39 PM7/25/19
to TiddlyWiki
Hello!
I am trying to build an Interactionmeckanism, were Useres can post and
On http://szen.io/Test/ it seems to work well... at least for me becaus the speed of the connection seems to have impact on this.
I allows to import texts from my server that can be seen in an Iframe in the sidebar, I hope this also works when you open it.

After all worked i transformed it into a plugin an entered it into other Wikis like https://www.szen.io/hak/ where it causes Network errors.
You can reproduce this by clicking one of the posts in $:/extensions/Interaction/ImportPosts

the reason seems to be $:/extensions/Interaction/macros/geturltxt.js
The Modal gets its Text when it is called with hardcoded url, but not something which is created and transcluded like this.
<$list filter="[[$:/Temp/URL]get[text]]" variable="url">
<$macrocall $name="geturltxt" url=<<url>> />
</$list>

Below is the code of the Macro. Do you have any suggestions to fix this?

Tschö+Merci:  Jan
/*\
title: $:/core/modules/macros/geturltxt.js
type: application/javascript
module-type: macro
Makro, das eine Textdatei darstellt
\*/

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

/*
Information about this macro
*/
   exports.name = "geturltxt";
   exports.params = [
      {name: "url"}
   ];

/*
Run the macro
*/
   exports.run = function(url) {
      var client = new XMLHttpRequest();
      var url = url.replace("+", "%20");
      client.open('GET', url, false);
       client.setRequestHeader('Content-type', 'Content-Type: text/html; charset=ISO-8859-1');
      client.onreadystatechange = function() {
    if (client.readyState == 4 && client.status == 200)
    {
      var urltext = unescape(client.responseText);
      var fields = {title: '$:/Temp/URL-Text', text: urltext}
       $tw.wiki.addTiddler(new $tw.Tiddler(fields))
    }
    }
client.send();
   };
})();

Mark S.

unread,
Jul 25, 2019, 1:13:31 PM7/25/19
to TiddlyWiki
Since you're using PHP, I can't test anything.

I suspect that the url is being passed as a title list, with [[ and ]], or that key characters are being stripped.

One way to see, would be to use

wait(url) ;

immediately after

function(url) { ....

Of course you have to save your change and reload for it to become active. I use this technique whenever I want to see exactly what the JS is "seeing". I suppose someone more advanced would write to the browser console.

Good luck!

Jan

unread,
Jul 25, 2019, 4:41:44 PM7/25/19
to tiddl...@googlegroups.com
Hi Mark,
thanks I think that is what I was looking for .
I ended up building a timeout function which was to hard for me to handle;-). This seems friendlier.
Thanks for the Idea with the console...to me that's little Ninja-Level but it sounds like a good idea.

I will check an Mail
Ahoi
--
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 tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d5770a6a-ad3b-4377-9c6d-fa1cda602ba2%40googlegroups.com.

Jan

unread,
Jul 25, 2019, 5:18:44 PM7/25/19
to tiddl...@googlegroups.com
Hi, I checked the console it is this what it Reads.
I think wait is not the right path because the bug happens in Tiddlywiki.

ReferenceError: wait is not defined
    error https://www.szen.io/hak/:24135
    onerror https://www.szen.io/hak/:24162
    onerror $:/plugins/felixhayashi/vis/vis.js:3

Might the bug be due to a parsingerror. Why does one wiki do this and the other one produces no problem onerror https://www.szen.io/hak/:24162  Or is it the ports of the Server. Looking at google this seems to be the case.

P-) Jan



Mark S.

unread,
Jul 25, 2019, 5:47:04 PM7/25/19
to TiddlyWiki
Sorry ... I should have said alert(url). I have no idea where "wait" came from. Don't sleep and type, I guess.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Jan

unread,
Jul 26, 2019, 4:53:35 AM7/26/19
to tiddl...@googlegroups.com
Hi Mark,
If I introduce alert it gives out the URL correctly, the mischief seems to happen later when the Http request cannot be rendered.
I am still wondering why it works on one site (http://szen.io/Test/)  but not on https://szenio.de/Neu/ thogh it is the same server and the same plugin.

Cheers! Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/747f19af-99bd-4b3a-8e9f-1ad976090521%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages