0

Im new into js (not into programing) and want to make a thing that I think is simple but I am struggling to make it.

Script sender

Basically: Script.js take the parameters of the url (I have this done) and I want that parameter to go to a other that operate with it (and a database value but that is for atoher day cause y know how to that) and return the value operate.

All of this is to make an operation in a page but no one can see the operation , just the imput and the output. Like the only visible files I want in my page is index.html and script.js , but not script2.

(Im open to use php but I have no idea how to use it so please simple :( )

Really sorry for my bad english

  • `script.js` sends an AJAX request to a backend (e.g. Node.js, Deno) that runs `script2.js`. – jabaa Feb 10 '22 at 11:30
  • I think you should have thought more about what you really want. However, I think if you want to stick with JavaScript and not include PHP into your application, then you can make use of Node.js. – Ahmad Alshaib Feb 10 '22 at 13:03
  • @AhmadAlshaib I can include PHP if is necesary , Im down to lear. If you have any solutions with php pls comment me – Juan Garcia Feb 10 '22 at 15:14
  • Why would you use PHP? `script2.js` is a JavaScript file. You need a JavaScript engine. – jabaa Feb 10 '22 at 15:15
  • @jabaa I have made that right now and it works well, but I have a problem that it makes de request perfectly but the response is blanck (not null but nothing) – Juan Garcia Feb 10 '22 at 15:15
  • 1
    That problem is unrelated to this question. You can write your complete backend using Node.js or Deno. Correct JavaScript-based backends send completely valid responses. – jabaa Feb 10 '22 at 15:16

1 Answers1

-1
  1. Solution 1

I don't really understand your problem but if you just want to call a function on script2.js and pass it Params from script.js you can just import it into script.js. See (How do I include a JavaScript file in another JavaScript file?).

  1. Solution 2

If you want your backend as you said in your comment to execute script2, it just needs to be an actual service or helper or whatelse accessible by your controllers.

  • 1
    Your first solution doesn't really work for linking a "front-end" JS file with a "back-end" JS file. Your second solution is so specific and you didn't mention the specification, whilst the question is kind of general. – Ahmad Alshaib Feb 10 '22 at 13:00