Return php values with javascript

Asked

Viewed 344 times

2

I in java made a project that in several parts of the program called a function to go to the database to fetch a value and return, of type String nome = acessocliente.obtemnome(id); where in the accessoclient class I had a parameter called obtemname that returns the client name by id.
Well I wanted to do it in Javascript and PHP.
In other words, somewhere in the Javascript code call php the type var nome = "obtemnome.php?id="+id;

How can I do that?

  • 1

    Suffice it to have the variable when the page loads or fetches from the comic after the page has loaded?

  • After the page has already loaded.

  • 1

    Take a look here: http://answall.com/a/25215/129, I think this is what you need, possibly with native JS.

  • As I later can pass the result to variable in that code?

1 answer

0


Could do so:

$("#div_qualquer").load("obtemnome.php",{id:id}, function(response){
   alert(response); //alerta a resposta obtida do PHP
});

The only change I made to your code was to pass the parameters via POST for PHP, however, if you prefer to pass via GET even, just recall this {id:id};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.