Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

how to post data with on load function with Jquery

Dear Experts,

I'd like to post the data to my php page. The below code works but I want to post it with on load function not with on click.
I want to post it when the page is loading.
How can I do that? thank you in advance.

I also want to remove the alert.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.post("test-post.php",
        {
          name: "Donald Duck",
          city: "Duckburg0922"
        },
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

you are great. thank you