-1

everyone, I am having a hard time understanding how AJAX works. If anyone could help me, I need that when a button with onclick="CallFunction()" is clicked, it would execute a PHP function CreateBet();

This is my only current HTML:

<html>
<div style="margin: 0 auto; width: 500px; height: 500px; border: 1px solid black;">
<button onclick="CreateBet()" type="button">Create Bet</button>
</div>
</html>

Thank you in advance :)

  • https://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php – Noman Apr 01 '18 at 09:09
  • `CreateBet` if your _javascript_ function - within it you can do an http request that result in the invocation of the `CreateBet` php function. You can just check one of the trillion examples online. – Federkun Apr 01 '18 at 09:10
  • simply call that file in your ajax request – Abslen Char Apr 01 '18 at 09:11

1 Answers1

0
<input type="button" name="c1" value="pt" onclick="filter()">

it will call the filter function of ajax.

function filterPrice() {

            $.ajax({
                url: "Filter.php", //url for php function
                type: "POST",
                data: sendData, // data to sent
                dataType: 'json',
                success: function (data)
                {

                }
            });
        }
Sachin Aghera
  • 486
  • 3
  • 8
  • Please explain if you can what this code does, because I still can't understand it. – Laurynas Čekanavičius Apr 01 '18 at 09:14
  • when you click button it will call the filter function of javascript and filter function of javascript will call the FIlter.php file which contain the php logic of your code. – Sachin Aghera Apr 01 '18 at 09:16
  • What does "success: function (data)" and "data: sendData, // data to sent" mean? – Laurynas Čekanavičius Apr 01 '18 at 09:18
  • type is used to define which method used("GET","POST","PUT") and data : sendData is used to sent the data suppose in post call you have to sent the data so it will use in put and post method and success function will return when response arrive success. – Sachin Aghera Apr 01 '18 at 09:21