【发布时间】:2011-07-25 14:02:09
【问题描述】:
在我的应用程序中,我有一个 ajax 调用,成功后它会将一些数据附加到现有的链接 href。
这很好用。问题是,如果我想再次运行 ajax 调用并在成功时附加一些不同的数据,它会从上一个 ajax 调用中获取 href 值 + 新值,然后再添加新数据。
我希望它在附加数据之前将数据添加到初始 href 值。
以下是我的代码: (出于测试目的,我每次都会附加示例样本值)
//get next page link value, so we can add filter to url
var next_link = $("a.next").attr("href");
$.ajax({
type: "POST",
url: "ajax_calls.php",
data: "instrument="+selected.val()+"&filter=true",
success: function(listing){$("#listings").html(listing);
$("a.next").attr("href", next_link + '&field=x');
},
error: function(){alert(3);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)}
});
对此的任何帮助将不胜感激。 谢谢
【问题讨论】:
标签: javascript jquery ajax append href