Reputation: 43
I'm new to jQuery and Ajax. I'm following a tutorial, and having a problem with this.
I have an anchor tag with id getcomments
and the following JavaScript:
<script>
$(function() {
$('#getcomments').click(function() {
$.ajax({
url : "req.html",
success : function(response) {
console.log(response);
}
});
return false;
});
});
And an HTML file called req.html
in the same folder with a mock comment.
When I inspect the log I only get the "document" in firebug, and no actual get request.
I've tried doing something actual in the success function also, appending the response.
Nothing happens, what am I doing wrong here?
Upvotes: 0
Views: 387
Reputation: 160321
If it's a local file it won't make a request.
That you see Document
in Firebug means it's working. Set the contents of a div to the response, after adding a dataType: "html"
to the Ajax call--it will be the contents of the HTML file.
$(function() {
$('#getcomments').click(function() {
$.ajax({
url : "req.html",
dataType : "html",
success : function(response) {
$("#foo").append(response);
console.log(response);
}
});
return false;
});
});
Upvotes: 1