ajax加载过的内容,通过Ajax加载内容

4 个答案:

答案 0 :(得分:3)

您想为链接设置ajax。要求:

为链接编写处理程序。

当有人点击某个链接(重定向到该页面)时,我们必须取消浏览器的默认行为。

删除从服务器收到的旧数据ajax并使#ajax-wrap保持新鲜。

通过ajax加载远程页面并将其设置为#ajax-wrap。

现在将其滑下来。

醇>

// Document Ready

$(function () {

// attaching click handler to links

$("a.home-right").click(function (e) {

// cancel the default behaviour

e.preventDefault();

// get the address of the link

var href = $(this).attr('href');

// getting the desired element for working with it later

var $wrap = $('#ajax-wrap');

$wrap

// removing old data

.html('')

// slide it up

.slideUp()

// load the remote page

.load(href + ' #content', function () {

// now slide it down

$wrap.slideDown();

});

});

});

答案 1 :(得分:1)

您可以像这样使用ajax:

$("a.home-right").click(function () {

$.ajax({

type: "get",

url: "YOUR URL HERE",

success: function(data){

$('#ajax-wrap').html(data);

$('#ajax-wrap').slideToggle();

},

error: function(){

alert("An error occured");

}

});

});

答案 2 :(得分:0)

使用get:

// Inside click handler

$.get('url_that_returns_data')

.done(function(response){

var $response = $(response);

$('#ajax-wrap').html($response.find('#content')).slideToggle();

});

答案 3 :(得分:0)

试试这个:

$(function(){

$("a.home-right").click(function () {

$('#ajax-wrap').slideUp();

var url = $(this).attr("href")

$.ajax({

type: "get",

url: url,

success: function(msg){

$('#ajax-wrap').html(msg)

$('#ajax-wrap').slideDown();

},

error: function(){

alert("An error occured");

}

});

})

})