Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery & Ajax: ReferenceError: ajax is not defined [closed]

I get a

ReferenceError: ajax is not defined

error in browser console when I try to make an ajax call.

I'm pretty sure I properly loaded the jQuery library, therefore I don't understand how can the $.ajax function not be defined.

Here is the HTML (without irrelevent css and markup):

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
    </head>
    <body>
        <div>
            <a class="getUsersA">Get users</a>
            <div id="gridD"></div>
        </div>
    </body>
</html>

Here is the script.js file:

$(document).ready(function() {
    $(".getUsersA").click(function() {
            $.ajax({
                url:ajax/getUsers.php,
                type:POST,
                data:({
                    id:0
                }),
                success:function(results) {
                    $("#gridD").html(results);
                }
            });
    });
});

Thank you for any help!

like image 287
user2807746 Avatar asked Mar 11 '26 18:03

user2807746


1 Answers

You need to wrap ajax/getUsers.php, in quotes. or else it would look for a local variable ajax rather than treating it as a string.

url: "ajax/getUsers.php",

Something like this:

$.ajax({
    url: 'ajax/getUsers.php',
    type: 'POST',
    data:({
        id: 0
    }),
    success:function(results) {
        $("#gridD").html(results);
    }
});
like image 162
karthikr Avatar answered Mar 14 '26 04:03

karthikr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!