我已经设置了航点,以便在触发时执行json帖子,但是网络服务器永远不会收到请求。我得到以下jquery错误。
TypeError:context为null http://mysite 5082行
我知道航点正在弄乱上下文,因为如果我删除航点,我可以执行后调用。 我也尝试删除所有数据和成功操作。
谁能看到我做错了什么?感谢。
$(document).ready(function() {
$('.product_row').waypoint(getDisplayRow);
});
function getDisplayRow()
{
var search_url = window.location.protocol + "//" + window.location.host + window.location.pathname;
var codes = [];
$(this.element).children().each(function() {
codes.push($(this).attr('product_id'));
});
$.post('/ajax/getproductdisplayrow/', {codes: codes,
subcategory_url: $('#subcategory_url').val(),
category_url: $('#category_url').val(),
show_color_squares: $('#show_color_squares').val(),
search_url: search_url
}, function(data) {
$(this.element).before(data);
$(this.element).remove();
adjustRowHeight();
});
}
这不起作用
$(document).ready(function() {
$('.product_row').waypoint(getDisplayRow);
});
function getDisplayRow()
{
$.post('/ajax/getproductdisplayrow/', {
}, function(data) {
});
}
我有最新版本的航点,以及jquery
答案 0 :(得分:0)
在回调POST中:
function(data) {
$(this.element).before(data);
$(this.element).remove();
adjustRowHeight();
});
this
不再是Waypoint实例。我相信这是帖子中的jqXHR实例。 this.element
返回未定义,当您尝试调用before
时,谁知道从那里发生了什么。您可以将此元素属性存储在外部函数中的变量中,并在POST回调中使用它:
function getDisplayRow()
{
var search_url = window.location.protocol + "//" + window.location.host + window.location.pathname;
var codes = [];
var $waypointElement = $(this.element);
$waypointElement.children().each(function() {
codes.push($(this).attr('product_id'));
});
$.post('/ajax/getproductdisplayrow/', {codes: codes,
subcategory_url: $('#subcategory_url').val(),
category_url: $('#category_url').val(),
show_color_squares: $('#show_color_squares').val(),
search_url: search_url
}, function(data) {
$waypointElement.before(data);
$waypointElement.remove();
adjustRowHeight();
});
}