# Http Get method in a Template node?

**URL:** https://discourse.nodered.org/t/http-get-method-in-a-template-node/19265
**Category:** Dashboard
**Created:** [17 December 2019 17:32 UTC](https://discourse.nodered.org/t/http-get-method-in-a-template-node/19265 "2019-12-17T17:32:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)
#### Post date: [17 December 2019 17:32 UTC](https://discourse.nodered.org/t/http-get-method-in-a-template-node/19265/1 "2019-12-17T17:32:08Z")

</div>

Hi guys,

I would like to create a button in a Template Node which sends a GET method (to turn the camera to a predefined position).  
For the curious it looks like that 😉  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6d5550bced2d0d50ef9f83f0d6f8c6df4f255bcc.png)  
Here is the html code for the N°2 button :

```auto
<button width="10px" eight="10px" type="button"
 onclick="http://user:pass@192.168.1.8/web/cgi-bin/hi3510/param.cgi?cmd=preset&-act=goto&-status=1&-number=2"
>2</button>

```

**Note** : the http link **works well with a Dashboard : Button + an http Request node set to GET method**

Can someone help me **find the code so that "onclick" can be a GET method?**

Thank you

---

<div class="post-metadata">

### Author: ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)
#### Post date: [22 December 2019 17:40 UTC](https://discourse.nodered.org/t/http-get-method-in-a-template-node/19265/2 "2019-12-22T17:40:10Z")

</div>

@BartButenaers purpose me this `ajax()` method :

```auto
      <button id="preset_1" width="10px" eight="10px" type="button">2</button> 
      <script>
         // Add your Javascript here, between the 'script' tags ...
         $(document).ready(function() {
            // As soon as the document is loaded, add a click event handler to your preset button
            $("#preset_1").click(function(e) {
               e.preventDefault();
$.ajax({type: "GET", url: "http://user:pass@192.168.1.8/web/cgi-bin/hi3510/param.cgi?cmd=preset&-act=goto&-status=1&-number=2",
            });
         });
      });
      </script>

```

**But Chrome don't give up for security reasons :**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4bb70830dcd78dec7542f8ddf27573ca6220cbbd.png)

> [@On another topic](https://discourse.nodered.org/t/19349/8):
>
> In that case you browse to your dashboard, and the javascript inside the dashboard will try to access your ip camera. Something like this:
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e029a4ae724784e2f59bd50dce6bee53711f3c31.png)
> 
> This might be a security issue, since the page you are visiting (in this case the dashboard) is sending you - behind your back without you knowing it - to another site, which you perhaps don't want... Modern browsers (especially Chrome) won't allow this: so it will give a CORS (= Cross-Origin Resource Sharing) exception. Summarized: you won't be able to access your camera from the dashboard.
> 
> Some workarounds:
> 
> - I think it is solved when you camera sends an "Access-control-allow-origin" http header, but don't think you can easily do that.
> - To workaround these CORS problems, I have developed some time ago the [node-red-contrib-http-proxy](https://github.com/bartbutenaers/node-red-contrib-http-proxy/) node: then you can send also your camera requests to your node-red flow, which will redirect the request to your camera. Only disadvantage I see is that your Raspberry will have to pass all the data...

**When I have more time and experience, as proposed** @andrei **I could study the Fetch API**

> [@On another topic](https://discourse.nodered.org/t/19313/4):
>
> ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f68e686f892652010fe1dcd0688831c143d46aec.png) [SitePoint – 19 Apr 18](https://www.sitepoint.com/introduction-to-the-fetch-api/)  
> ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/46f7c875d6cd9a9d27cc9ac0983a8283b984fdd7.jpeg)
> 
> ### [Introduction to the Fetch API — SitePoint](https://www.sitepoint.com/introduction-to-the-fetch-api/)
> 
> Ludovico Fischer introduces you to the Fetch API, a new standard that aims to unify fetching across the web and to replace XMLHttpRequest.  
> [Learn Fetch API In 6 Minutes](https://www.youtube.com/watch?v=cuEtnrL9-H0)

**But meanwhile, the only thing that I found that works but is not at all sexy, is the use of the `<form>` tag with which I can access my request, without security alert:**

```auto
<form action = "http://user:pass@192.168.1.8/web/cgi-bin/hi3510/param.cgi?" target = "_ blanc" method = "GET">
            <input type = "text" name = "cmd" value = "preset">
            <input type = "text" name = "- act" value = "goto">
            <input type = "text" name = "- status" value = "1">
            <input type = "text" name = "- number" value = "1">
            <input type = "submit" value = "Go!">
</form>

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4fcbe7853e0769fe2a136beabe5070a18fa03ae7.png)  
...but open a new [succeed] tab 😩

**Question : is it possible to format this last code so that only one or more buttons are displayed, AND not to open a new tab [succeed]?**
