skip to Main Content

i want to get data form database using ajax, but it doesn’t work. what should i change?

function getdata()
    {
        alert();
        $.ajax
        ({
            type:'post',
            url:'view.php', 
            data:{
                num: "num",
                name : "name", 
                univ : "univ",
                ex: "ex",
                line : "line"
            },
            success: function(response)
            {
                alert(response);
                // if (response!=""){
                //  $("#table").html(response);
                // }
            }
        });
    }

and this is the button

<input type="submit" name="submit" onclick="getdata()" value="Submit"/>

the error called “ajax is not a function”. thank you

2

Answers


  1. What happens when you make the same request with a tool such as postman?

    We’re going to need a little more context to form be helpful.

    Login or Signup to reply.
  2. A little demo to show that it basically works once you include jQuery:

    function getdata()
    {
        $.ajax
        ({
            type:'post',
            url:'https://jsonplaceholder.typicode.com/posts', 
            data:{
                num: "num",
                name : "name", 
                univ : "univ",
                ex: "ex",
                line : "line"
            },
            success: function(response)
            {
                alert(JSON.stringify(response));
    if (response!=""){
     
     $("#out").html(JSON.stringify(response));
    }
            }
        });
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="submit" name="submit" onclick="getdata()" value="Submit"/>
    <pre id="out"></pre>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search