Reputation: 1
Performing a basic AJAX request, but when the HTML is displayed no HTML links work and now CSS:hover elements work either.
Confused as to what I've done wrong. Here's an example of the code below.
CSS:
li:hover{ background:red; }
a{ text-decoration:none; }
a:hover{ text-decoration:underline; }
HTML (index.php):
<script>
$(document).ready(function(){
ajax();
});
</script>
<ul class="loadhere"></uL>
loadthis.php:
<li><a href="">Example</a></li>
JS (AJAX):
function ajax(){
$.ajax({
type:"POST",
url:"http://example.com/loadthis.php",
dataType: "html"
})
.done(function(result){
$('ul.loadhere').html(result);
});
}
Upvotes: 0
Views: 574
Reputation: 11
You need to use the "success" option of ajax function, take off the done function and insert the function in success option in ajax object, like this:
function ajax(){
$.ajax({
type:"POST",
url:"http://example.com/loadthis.php",
dataType: "html" ,
success: function(result){
$('ul.loadhere').html(result);
}
});
}
Upvotes: 1
Reputation: 320
Try this
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
$(function(){
ajax();
function ajax(){
$.get('loadthis.php', {}, function(){
}).done(function(result){
$('ul.loadhere').html(result);
});
}
});
</script>
Upvotes: 0