0

I am new to javascript. I have one label, What I am doing is to get id using javascript which I am saving in a variable.

What I want is to send that variable to php page, where it will compare that id with mysql database id and returns it's data(some text) to javascript, it will then set it to label.

I would have used text file which is easiest way but some says this isn't a secure way to do this.

So how can I achieve this ?

Any help is appreciated, Thanks in advance.

Snappy
  • 203
  • 4
  • 18
  • 1
    Go watch some tutorials first :D – DaAmidza Jul 18 '17 at 21:10
  • AJAX is very possible in JS using XMLHttpRequest, but I advise using jQuery for that. – Mingle Li Jul 18 '17 at 21:11
  • AJAX is the way to go, it will allow you to pass data from the javascript (using jQuery) to php and pass the result back to the javascript. – Michael Bellamy Jul 18 '17 at 21:12
  • 2
    I recommend _not_ using jQuery, if all you're going to do is an ajax request. Adding a 100kb lib as a dependency for something you can do with 8 lines of vanilla JS seems silly. It's better to start by learning the language for real. – M. Eriksson Jul 18 '17 at 21:12
  • thanks @MagnusEriksson, would you please just show me a simple example how can I redirect to php using vanilla JS and get data back ? – Snappy Jul 18 '17 at 21:31
  • 1
    Use Google. There are _tons_ of examples and tutorials for that. Just search for "ajax example -jquery" (to remove all jquery related hits). If you want to learn programming, you need to learn how to do the research (which is a big part of learning, no matter how long you've been programming). – M. Eriksson Jul 18 '17 at 21:33

0 Answers0