开发者

passing a variable to a ajax request Jquery

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 开发者_如何学Gourls. 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜