user3285189
user3285189

Reputation: 1

What is wrong with this ajax code

Why does it not print "Hello" in my browser?

I have this code in a file called index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Learning Ajax</title>
    </head>
    <body>
        <h1>Learning Ajax</h1>
        <a href="files/ajax.txt">Load Ajax Text File</a>
        <script src="js/main.js"></script>
    </body>
</html>

and also this code in a file called main.js

var message = "Hello";

$(function() {
    var message = "Goodbye";
})();

alert(message);

its a self invoking anonymous function

Upvotes: -1

Views: 51

Answers (2)

shmuli
shmuli

Reputation: 5192

There's no AJAX in the code above. I recommend visiting jQuery's learning website and finding out what AJAX is all about and how it works: http://learn.jquery.com/ajax/.

Upvotes: 0

Danil Speransky
Danil Speransky

Reputation: 30463

Because of error: you use $, but there is no such function you have defined.

Upvotes: 2

Related Questions