0

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);      
});
}
hbowley
  • 1
  • 2
  • How looks like 'result'? – A. Wolff May 23 '13 at 10:18
  • possibly the paths are relative to the example.com/loadthis.php - so it can't find the css file. You can change the paths to absolute, so for the CSS for example: http://example.com/css/style.css – Seer May 23 '13 at 10:19
  • If you take ajax out of the question for now and just add an `
  • ` to the list does the CSS work for that?
  • – Alex May 23 '13 at 10:22
  • 2
    The provided code works - http://jsfiddle.net/3WBbn/ – Andreas May 23 '13 at 10:29
  • 1
    As @Andreas said, this should work... unless you are cross-domain! – mg007 May 23 '13 at 10:33
  • @AlexThomas Yes, the CSS works perfect when not fetched via AJAX. – hbowley May 23 '13 at 10:40
  • @roasted What do you mean? – hbowley May 23 '13 at 10:41
  • Would this have any effect on it?: `RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?page=$1 [NC,L]` – hbowley May 23 '13 at 10:49
  • try using a relative path like `url:"loadthis.php"`, and add `.fail()` to see if the request could be sent. – Spokey May 23 '13 at 10:55
  • @spokey tried, results still same. No fail requests. – hbowley May 23 '13 at 11:18
  • do u mind to use jQuery ajax? – Mahesh May 30 '13 at 12:56