jquery航路点post上的上下文问题
我已经设置了路径点,以便在触发时发布json,但是Web服务器从未收到请求。我得到以下jquery错误 TypeError:上下文为空 第5082行 我知道航路点会干扰上下文,因为如果我删除航路点,我可以执行post调用。 我还尝试删除所有数据和成功操作 有人能看出我做错了什么吗?谢谢jquery航路点post上的上下文问题,jquery,jquery-waypoints,.post,Jquery,Jquery Waypoints,.post,我已经设置了路径点,以便在触发时发布json,但是Web服务器从未收到请求。我得到以下jquery错误 TypeError:上下文为空 第5082行 我知道航路点会干扰上下文,因为如果我删除航路点,我可以执行post调用。 我还尝试删除所有数据和成功操作 有人能看出我做错了什么吗?谢谢 $(document).ready(function() { $('.product_row').waypoint(getDisplayRow); }); function getDisplayR
$(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:
function(data) {
$(this.element).before(data);
$(this.element).remove();
adjustRowHeight();
});
此
不再是航路点实例。我相信这是帖子中的jqXHR实例this.element
返回时未定义,当您尝试在前面调用时,谁知道会发生什么。您可以将此元素属性存储在外部函数中的变量中,并在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();
});
}
谢谢你的回复。我试过了。我还尝试将元素传递给getDisplayRow。那也没用。