Post codeblock code to external playground like JDoodle

Hi. My end goal is to have a button inside or under a codeblock and when pressing the button the code will open in JDoodle. JDoodle writes that you can do it by doing a Form and Post it, see here: Online Compiler and Editor/IDE for Java, C, C++, PHP, Python, Ruby, Perl - Code and Run Online.

What I have tested is to have a button (Buttons plugin) that triggers this code using Templater plugin:

function open_jdoodle () {
  let code = `int x = 10;`;
  let form = document.createElement("form");
  form.action = "https://www.jdoodle.com/api/redirect-to-post/compile-c-sharp-online";
  form.method = "post";
  form.target = "_blank";
  document.body.appendChild(form);
  let textarea = document.createElement("textarea");
  textarea.name = "initScript";
  textarea.append(code);
  form.appendChild(textarea);
  //NOTE: BROWSER MUST ALLOW POPUPS
  form.submit();
  console.log(form);
  form.remove();
}
module.exports = open_jdoodle;

I have run the same code in a client web app and it works, but what happens now is that JDoodle web page opens and gives the error:

errorCode	"INVALID_INPUT"
message	"Invalid Input"
errors	
0	"Request method 'GET' is not supported"
  • First step is to post test code to JDoodle and get that to work.
  • Next step is to be able to find the correct codeblock when you press the button and post that code to JDoodle.

Anyone have any ideas how to do it?

where did you copy the code from?
it’s not supposed to be fired through templater but through quickadd, no?

The code is copied from another old Docusaurus project I have that does what I want when it is running in a regular browser. Now I want to do the same but in Obsidian.

I’m new to Obsidian so I’m not familiar with quickadd.

I made a small node express server running on port 3000:

app.post('/post', (req, res) => {
    console.log(req.body);
    res.send('Hello post!');
});

app.get('/get', (req, res) => {
    console.log(req.body);
    res.send('Hello get!');
});
  • In open_jdoodle when I change form.action to:
    form.action = "http://localhost:3000/post";
    
    and click the button, a new browser window on ``localhost:3000/post` opens with message:
    Cannot GET /post
    
  • In open_jdoodle when I change form.action to:
    form.action = "http://localhost:3000/get";
    
    and click the button, a new browser window on ``localhost:3000/get` opens with message:
    Hello get!
    

Note that form.method = "post"; in both examples.

So it seems that form.method = "post"; is ignored and and get is always made. Any ideas how to force a post?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.