jQuery将变量从href传递到load() [英] JQuery Passing Variable From href to load()
问题描述
我正在尝试将jref id传递给JQuery中的load(),我可以从警报中看到返回的id#960,所以我知道id值已经过去了,只是不知道如何附加负载url,$(#refreshme _" + add_id)是重要的部分,我用它来刷新数据库请求分配的页面中唯一的div id,因此它将寻找id ="refreshme_960".我的简单示例显然不起作用.我想刷新显示新车列表的页面的db select部分.有什么想法吗?
I am trying to pass an href id to load() in JQuery, I can see from the alert the returned id# 960, so I know the id value is getting past I just don't know how to append the load url, well the $("#refreshme_"+add_id) is the important part, I use that to refresh the unique div id in the page assigned by the database pull, so it would be looking for id="refreshme_960". My simple example that is obviously not working. I want to refresh the db select part of the page showing the new list of cars. Any ideas?
$(document).ready(function()
{
$(".add_to_favorites").livequery("click", function(event)
{
var add_id = this.id.replace("add_", ""); //taken from a.href tag
alert (id);
$.get(this.href, function(data)
{
$("#refreshme_"+add_id).load("http://www.example.com/car_list/"+add_id);
<a class="add_to_cars" href="/car-add/960/add'}" id="add_960">Add Car</a>
推荐答案
您正在此行中使用append()
You are using append() in this line
$('#favorite-listings').append(response);
这就是为什么您要在旧结果之后添加新结果的原因.将该行更改为
Which is why you get new results added after the old ones. Change that line to
$('#favorite-listings').html(response);
这篇关于jQuery将变量从href传递到load()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!