views:

74

answers:

2

Hello, I am trying to pass a variable to an ajax request via jquery. I have a triggered event that defines the variable. I want to do this so that I can have one ajax request handle multiple urls. I have alerted the url and it come back fine, but when I plug it into the URL slot of a $.ajax request my targeted content does not load. Here is my code.

$(document).ready(function(){

   $('a').live('click', function(){
      var link = $(this).attr("href");
       $.ajax({
           url: link,
           success: function(html){
                $('#load').html(html)
           }
      });
   });

});

this has been a real headache and I feel I am just misusing something. Please help.

+1  A: 

What URL are you passing in? If it is for a different domain the AJAX call will not be executed.

Justin Ethier
no its a path in the same server. Im passing through simple things like link1.html, link2.hmtl thanks
Jacob Lowe
+1  A: 

There is a shortcut for this using .load() :)

$('a').live('click', function(){
  $('#load').load($(this).attr("href"));
});

Be aware of the same origin policy that Justin is alluding to as well, requests to different domains are prohibited for security reasons.

Nick Craver
thanks for the shortcut sadly the the content still does not show. The thanks i have tried the load method not in this format (which is cleaner :])but it still does not work.
Jacob Lowe
@user304735 - Can you host some sample HTML this is being run on?
Nick Craver
nvm. i have it working stupid mistake on my part
Jacob Lowe