S
S
Sergey2021-04-25 19:21:29
AJAX
Sergey, 2021-04-25 19:21:29

How to pull PHP variable from .php file to .html file using AJAX?

There is index.html and file.php
There is a simple variable in file.php: It is necessary that in index.html visitors see this "dog" on button click. The problem is that I have never worked with AJAX, I need to do it without reloading. PS: You can use jQuery ^-) PPS: I understand that the question is from the category of "go and read the tutorials". But right now there is no time for that, alas. There are hefty sheets of codes everywhere on the Internet.
$password="dog";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2021-04-25
@Shull

on the php server, the file should return, for example, json
echo json_encode($my_cool_object);
on the client, jquery should make a request

$.get('my_cool.php',function(data){alert(data);},'json')

L
Luigi, 2021-04-25
Wampa @Annikangl

You need to write code like this

<script>
var btn = $('#my_btn').text;
btn.click = getPasswrod();

function getPassword(){
    var myInput = $('#rny_input').val();
    $.ajax({
        type: "POST",
        url: "my_file_handler.php",
    }).done(function( result )
        {
            myInput = result;
        });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question