D
D
Dmitry2014-05-10 15:58:26
PHP
Dmitry, 2014-05-10 15:58:26

How to pass a value from JS to PHP without reloading the page?

There is a page. It is necessary that when clicking on a certain element, a variable with the value n is passed to php. Next, the PHP script is executed and again, without reloading the page, a block is loaded into html, the id of which corresponds to the value of the passed variable. Need logic or implementation example. I'm not familiar with AJAX and JSON, but if you point me in the right direction, I think I'll figure it out. Thanks to all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Obrezkov, 2014-05-10
@another_dream

Running here :)

D
Dmitry, 2014-05-10
@another_dream

$.ajax({
  type: 'POST',
  url: 'response.php?action=sample2',
  data: 'name=Andrew&nickname=Aramis',
  success: function(data){
    $('.results').html(data);
  }
});

An example of how to implement. The PHP script will receive POST data (name and nickname). Further processing and return of result. Right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question