0

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

user3783243
  • 5,368
  • 5
  • 22
  • 41

2 Answers2

0

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.

Sean Morris
  • 384
  • 2
  • 9
0

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>
Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43