Javascript troubles

What I’m trying to do:
import a javascript function, placed it in native libs and standard-page

What I’ve tried and what’s not working:
was working , now its not and i’m sick of my stupidity at this time …

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
https://anvil.works/build#clone:F3BFZPIMK57BO2XW=CD7GVHCFIBZSDRT6OSI7HUQ6
share a copy of your app

I took a quick look and I think the issue is with how you are trying to call the function from Python. Have you reviewed the docs and/or looked at other examples on the Forum calling a JavaScript function from client code?

1 Like

Frustratingly there’s no syntax highlighting in native library script tags.

You’re missing a bracket.
This means that the script in native libraries fails to compile.
So that function doesn’t exist.

  
function retGitJS() {
 fetch('https://api.github.com/repos/javascript-tutorial/en.javascript.info/commits')
  .then(response => response.text())
  .then(commits => alert(response); // missing a bracket here
  //.then(commits => alert(commits[0].author.login));
}

If you’re using javascript the browser console is something to always check.

Errors in native libraries can’t really be reported by anvil because anvil hasn’t loaded when native libraries executes.

3 Likes

Frustratingly there’s no syntax highlighting in native library script tags.

You’re missing a bracket.
This means that the script in native libraries fails to compile.
So that function doesn’t exist.

Interesting , i assumed if i had 3 functions between the tags
with syntax error in one , the others would compile. I was completely wrong !!!

thanks a million @stucork

1 Like

On a side note, when i enable the javascript debugger i get a mess of connection refused errors
trying to access http://localhost:1616/webpack_hmr , i assume this must be some kind of
javascript debugger “webpack” ? Is this an anvil thing ? or should i set this up ? or ignore it…

GET http://localhost:1616/hmr/__webpack_hmr net::ERR_CONNECTION_REFUSED

If you’re using the browser console it’s best to do it when you’re running the app in a new tab

1 Like